home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / fweb / fweb-1.40 / web / fweave.web < prev    next >
Text File  |  1993-10-29  |  203KB  |  8,267 lines

  1. @z --- fweave.web ---
  2.  
  3. FWEB version 1.40 (October 30, 1993)
  4.  
  5. Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]
  6.  
  7. @x-----------------------------------------------------------------------------
  8.  
  9.  
  10. \Title{FWEAVE.WEB} % The FWEAVE processor.
  11.  
  12. @c
  13.  
  14. @* INTRODUCTION.  \WEAVE\ has a fairly straightforward outline.  It
  15. operates in three phases: first it inputs the source file and stores
  16. cross-reference data, then it inputs the source once again and produces the
  17. \TeX\ output file, and finally it sorts and outputs the index.  It can be
  18. compiled with the optional flag |DEBUG| (defined in \.{typedefs.web}).
  19.  
  20. Some compilers may not be able to handle a module this big. In that case,
  21. compile this twice, defining from the compiler's command line the macro
  22. |part| to have the value of either~1 or~2: e.g., `\.{-Dpart=1}'. See the make
  23. file for complete details.
  24.  
  25. For the text of the modules that aren't printed out here, such as
  26. \.{typedefs.web}, see \.{common.web}.
  27.  
  28. @m _FWEAVE_ // Identify the module for various \FWEB\ macros.
  29. @d _FWEAVE_h
  30. @d _FWEB_h
  31.  
  32. @A 
  33. @<Possibly split into parts@>@; // Defines |part|.
  34.  
  35. @<Include files@>@;
  36. @<Typedef declarations@>@;
  37. @<Prototypes@>@;
  38. @<Global variables@>@;
  39.  
  40. /* For pc's, the file is split into three compilable parts using the
  41. compiler-line macro |part|, which must equal either~1, 2, or~3. */
  42. #if(part == 0 || part == 1)
  43.     @<Part 1@>@;
  44. #endif // |Part == 1|
  45.  
  46. #if(part == 0 || part == 2)
  47.     @<Part 2@>@;
  48. #endif // |part == 2|
  49.  
  50. #if(part == 0 || part == 3)
  51.     @<Part 3@>@;
  52. #endif // |part == 3|
  53.  
  54. @ Here is the main program.  See the user's manual for a detailed
  55. description of the command line.
  56.  
  57. @<Part 1@>=@[
  58.  
  59. int main FCN((ac, av))
  60.     int ac C0("Number of command-line arguments.")@;
  61.     outer_char **av C1("Array of pointers to command-line arguments.")@;
  62. {
  63. /* --- Various initializations --- */
  64. ini_timer(); /* Start timing the run. */
  65.  
  66. argc=ac; @+ argv=av; /* Remember the arguments as global variables. */
  67.  
  68. ini_program(weave);
  69.  
  70.   common_init();
  71.   @<Set initial values@>;
  72.  
  73. /* --- Do the processing --- */
  74.   phase1(); /* read all the user's text and store the cross-references */
  75.   phase2(); /* read all the text again and translate it to \TeX\ form */
  76.   phase3(); /* output the cross-reference index */
  77.  
  78. /* --- Finish up --- */
  79.   if(statistics) see_wstatistics(); // Invoked by command-line option~\.{-s}.
  80.  
  81. return wrap_up(); /* We actually |exit| from here. */
  82. }
  83.  
  84. @I typedefs.hweb
  85.  
  86. @ Here we open the \.{.tex} output file.  This routine is called from
  87. |common_init|. 
  88.  
  89. @<Part 1@>=@[
  90.  
  91. SRTN open_tex_file(VOID)
  92. {
  93. if(STRCMP(tex_fname,"stdout") == 0) tex_file = stdout;
  94. else if((tex_file=FOPEN(tex_fname,"w"))==NULL)
  95.     FATAL("!! Can't open output file ", tex_fname);
  96. else @<Print header information to beginning of output file@>@;
  97. }
  98.  
  99. @ The command line was formatted up with newlines; these must be followed
  100. by a \TeX\ comment character.
  101. @<Print header...@>=
  102. {
  103. fprintf(tex_file,"%% FWEAVE v%s (%s)\n\n",version,release_date);
  104. }
  105.  
  106.  
  107. @
  108. @<Set init...@>=
  109.  
  110. @<Allocate dynamic memory@>@;
  111.  
  112. @ The function prototypes must appear before the global variables.
  113. @<Proto...@>=
  114.  
  115. #include "w_type.h" /* Function prototypes for \FWEAVE. */
  116.  
  117. @i xrefs.hweb /* Declarations for cross-referencing. */
  118.  
  119. @
  120. @<Alloc...@>=
  121.  
  122. ALLOC(xref_info,xmem,ABBREV(max_refs),max_refs,0);
  123. xmem_end = xmem + max_refs - 1;
  124.  
  125. @
  126. @<Set init...@>=
  127.  
  128. name_dir->xref = (XREF_POINTER)(xref_ptr=xmem); 
  129. xref_switch = mod_xref_switch = defd_switch = index_short = NO;
  130. xmem->num = 0; // Cross-references to undefined modules.
  131.  
  132. @ A new cross-reference for an identifier is formed by calling |new_xref|,
  133. which discards duplicate entries and ignores non-underlined references to
  134. one-letter identifiers or reserved words.
  135.  
  136. If the user has sent the |no_xref| flag (the \.{-x} option of the command
  137. line), it is unnecessary to keep track of cross-references for identifers.
  138. If one were careful, one could probably make more changes around module~100
  139. (??) to avoid a lot of identifier looking up.
  140.  
  141. @<Part 1@>=@[
  142.  
  143. SRTN new_xref FCN((part0,p))
  144.     PART part0 C0("")@;
  145.     name_pointer p C1("")@;
  146. {
  147. xref_pointer q; // Pointer to previous cross-reference.
  148. sixteen_bits m, n; // New and previous cross-reference value.
  149.  
  150. if(index_flag == NO)
  151.     {
  152.     SET_TYPE(p,DEFINED_TYPE(p) | 0x80);
  153.     index_flag = BOOLEAN(!(language==LITERAL));
  154.     }
  155.  
  156. /* Do nothing if we're not supposed to cross-reference. Also do nothing if
  157. we're inside a \&{format} statement. This is a bit kludgy, but it works. */
  158. if (!index_flag || !output_on || in_format)
  159.     return; /* The |output_on| flag    here prevents index entries for
  160.         modules skipped with~\.{-i}. */ 
  161.  
  162. index_flag = BOOLEAN(!(language==LITERAL));
  163.  
  164. /* Say where the identifier is defined (but not if it's a reserved word). */
  165. if(defd_switch && (part0 == DEFINITION 
  166.         || !(is_reserved(p) || is_intrinsic(p) || is_keyword(p)))) 
  167.     {
  168.     sixteen_bits mod_defined = p->defined_in(language);
  169.  
  170.     if(mod_defined && mod_defined != module_count)
  171.         {
  172.         err_print(W,"Identifier in %s was already explicitly \
  173. or implicitly marked via @@[ as defined in %s",
  174.             MOD_TRANS(module_count), MOD_TRANS(mod_defined));
  175.         mark_harmless;
  176.         }
  177.  
  178.     p->defined_in(language) = module_count;
  179.     SET_TYPE(p,defd_type);
  180.     defd_switch = NO;
  181.     }
  182.  
  183. if ( xref_switch==NO 
  184.         && (is_reserved(p) || ((!index_short) && (length(p)==1))) )
  185.     return;
  186.  
  187. if(index_short)
  188.     index_short = NO;
  189.  
  190. if(no_xref) 
  191.     return; // The result of the \.{-x} flag.
  192.  
  193. m=module_count+xref_switch; xref_switch=NO; q = (xref_pointer)p->xref;
  194.  
  195. if (q != xmem)
  196.     {  /* There's already an entry. */
  197.     n = q->num;
  198.  
  199.     if (n==m || n==m+def_flag) 
  200.         goto check_implicit; 
  201.             // Discard duplicates within the same module.
  202.     else if (m==n+def_flag) 
  203.         {
  204.         q->num = m; /* Update the entry to be defined instead of
  205. just used. */
  206.         goto check_implicit;
  207.         }
  208.     }
  209.  
  210. /* There's no entry yet; make a new cross-reference. */
  211. append_xref(m);
  212.  
  213. /* Link in; highest module number is first. */
  214. xref_ptr->xlink=q; p->xref = (XREF_POINTER)xref_ptr;
  215.  
  216. check_implicit:
  217.   if(typd_switch) 
  218.     @<Execute an implicit \.{@@f}@>@;
  219. }
  220.  
  221. @ When the |typd_switch| is on, due to an~\.{@@`}, we execute an implicit
  222. format statement that formats~|p| as a reserved word.
  223. @<Execute an implicit...@>=
  224. {
  225. NAME_INFO rs_wd;
  226. name_pointer lhs = p, rhs = &rs_wd;
  227.  
  228. rhs->ilk = int_like;
  229. rhs->reserved_word = YES;
  230. rhs->Language = BOOLEAN(language);
  231. rhs->intrinsic_word = rhs->keyword = NO;
  232.  
  233. @<Format the left-hand side@>@;
  234.  
  235. @#if 0
  236. /* Mark as defined in this module. */
  237. if(mark_defined.imp_reserved_name)
  238.     {
  239.     p->defined_in(language) = module_count;
  240.     SET_TYPE(p,IMPLICIT_RESERVED);
  241.     }
  242. @#endif
  243.  
  244. /* Make all previous entries register as defined, not just used. */
  245. for(q=(xref_pointer)p->xref; q>xmem; q = q->xlink)
  246.     if(q->num < def_flag) q->num += def_flag;
  247.  
  248. typd_switch = NO;
  249. }
  250.  
  251. @ The cross-reference lists for module names are slightly different.
  252. Suppose that a module name is defined in modules~$m_1$, \dots, $m_k$ and
  253. used in modules~$n_1$, \dots, $n_l$. Then its list will contain
  254. $m_1+|def_flag|$, $m_k+|def_flag|$, \dots, $m_2+|def_flag|$, $n_l$, \dots,
  255. $n_1$, in this order.  After Phase II, however, the order will be
  256. $m_1+|def_flag|$, \dots, $m_k+|def_flag|$, $n_1$, \dots, $n_l$.
  257.  
  258. @<Part 1@>=@[
  259.  
  260. SRTN new_mod_xref FCN((p))
  261.     name_pointer p C1("")@;
  262. {
  263.   xref_pointer q,r; /* pointers to previous cross-references */
  264.  
  265. @#if(0)
  266. if(!output_on) return; /* Don't bother with references if the module is
  267.             skipped with \.{-i}. */
  268. @#endif
  269.  
  270.   q = (xref_pointer)p->xref; r=xmem;
  271.  
  272.   if (q>xmem) 
  273.     {
  274. /* ``Used in module...'' Scan past all the definitions. */
  275.     if (mod_xref_switch==NO) 
  276.         while (q->num>=def_flag) 
  277.             {
  278.             r=q; q=q->xlink;
  279.             }
  280.     else /* Defining...*/
  281.         if (q->num>=def_flag) 
  282.             {
  283.             r=q; q=q->xlink;
  284.             }
  285.     }
  286.  
  287. /* Discard duplicate ``used in'' xref. */
  288. if(mod_xref_switch == NO && q->num == module_count) 
  289.     return;
  290.  
  291.   append_xref(module_count+mod_xref_switch);
  292.   xref_ptr->xlink=q; mod_xref_switch=NO;
  293.  
  294.   if (r==xmem) 
  295.     p->xref = (XREF_POINTER)xref_ptr;
  296.   else 
  297.     r->xlink=xref_ptr;
  298. }
  299.  
  300. @i tokens.hweb /* Declarations for |token| storage. */
  301.  
  302. @
  303. @<Alloc...@>=
  304.  
  305. ALLOC(token,tok_mem,ABBREV(max_toks_w),max_toks,0);
  306. tok_m_end = tok_mem+max_toks-1; // End of |tok_mem|./
  307.  
  308. ALLOC(token_pointer,tok_start,ABBREV(max_texts),max_texts,0);
  309. tok_end = tok_start+max_texts-1; // End of |tok_start|.
  310.  
  311. @<Set init...@>=
  312.  
  313. @<Initialize |tok_ptr|, |tok_start|, and |text_ptr|@>@;
  314. mx_tok_ptr=tok_ptr; mx_text_ptr=text_ptr;
  315.  
  316. @
  317. @<Initialize |tok_ptr|...@>=
  318. {
  319. tok_ptr = tok_mem + 1;
  320. tok_start[0] = tok_start[1] = tok_ptr;
  321. text_ptr = tok_start + 1;
  322. }
  323.  
  324. @ The |names_match| function is called from |id_lookup| in \.{common.web}
  325. when deciding whether to put a name into the table.
  326.  
  327. @<Part 1@>=@[
  328.  
  329. boolean names_match FCN((p,first,l,t))
  330.     name_pointer p C0("Points to the proposed match.")@;
  331.     CONST ASCII HUGE *first C0("Position of first character of string.")@;
  332.     int l C0("Length of identifier.")@;
  333.     eight_bits t C1("Desired ilk.")@;
  334. {
  335.   if (length(p)!=l) return NO; /* Speedy return. */
  336.  
  337.   if ( (p->Language&(boolean)language) && (p->ilk!=t) && !(t==normal &&
  338. is_reserved(p))) 
  339.         return NO; 
  340.  
  341.   return (boolean)(!STRNCMP(first,p->byte_start,l));
  342. }
  343.  
  344. @ The following two functions are used in initializations; they are called
  345. from \.{common.web}.
  346.  
  347. @<Part 1@>=@[
  348.  
  349. SRTN ini_p FCN((p,t))
  350.     name_pointer p C0("")@;
  351.     eight_bits t C1("")@;
  352. {
  353.   p->ilk=t; p->xref = (XREF_POINTER)xmem;
  354. }
  355.  
  356. SRTN ini_node FCN((node))
  357.     CONST name_pointer node C1("")@;
  358. {
  359. node->xref = (XREF_POINTER)xmem;
  360.  
  361. @<Initialize |mod_info| and |Language|@>@;
  362. }
  363.  
  364. @i ccodes.hweb /* Category codes for the reserved words. */
  365.  
  366. @* LEXICAL SCANNING.  Let us now consider the subroutines that read the
  367. \.{WEB} source file and break it into meaningful units. There are four such
  368. procedures: |skip_limbo| simply skips to the next `\.{@@\ }' or `\.{@@*}'
  369. that begins a module; |skip_TeX| passes over the \TeX\ text at the
  370. beginning of a module; |copy_comment| passes over the \TeX\ text in a \cee\
  371. comment; and |get_next|, which is the most interesting, gets the next token
  372. of a \cee\ text.  They all use the pointers |limit| and |loc| into the line
  373. of input currently being studied.
  374.  
  375. Control codes in \.{WEB}, which begin with~`\.{@@}', are converted into a
  376. numeric code designed to simplify \WEAVE's logic; for example, larger
  377. numbers are given to the control codes that denote more significant
  378. milestones, and the code of |new_module| should be the largest of all. Some
  379. of these numeric control codes take the place of ASCII control codes that
  380. will not otherwise appear in the output of the scanning routines.  
  381. @^ASCII code@>
  382.  
  383. The following table shows the assignments:
  384. $$\def\:{\char\count255\global\advance\count255 by 1}
  385. \def\Hrule{\noalign{\hrule}}\def\HHrule{\noalign{\hrule height2pt}}
  386. \def\Width{60pt}
  387. \count255='40
  388. \vbox{
  389. \hbox{\hbox to \Width{\it\hfill0\/\hfill}%
  390. \hbox to \Width{\it\hfill1\/\hfill}%
  391. \hbox to \Width{\it\hfill2\/\hfill}%
  392. \hbox to \Width{\it\hfill3\/\hfill}%
  393. \hbox to \Width{\it\hfill4\/\hfill}%
  394. \hbox to \Width{\it\hfill5\/\hfill}%
  395. \hbox to \Width{\it\hfill6\/\hfill}%
  396. \hbox to \Width{\it\hfill7\/\hfill}}
  397. \vskip 4pt
  398. \hrule
  399. \def\!{\vrule height 10.5pt depth 4.5pt}
  400. \halign{\hbox to 0pt{\hskip -24pt\WO{\~#}\hfill}&\!
  401. \hbox to \Width{\hfill$#$\hfill\!}&
  402. &\hbox to \Width{\hfill$#$\hfill\!}\cr
  403. 00&\\{ignore}&\MM &\\{verbatim}&\\{force\_line}&\WW    &**     &\CC    &\\{bell}\cr\Hrule
  404. 01&\dots  &\\{begin\_cmnt}&\\{lf} &\PP    &\\{ff} &\\{cr}
  405.     &\\{begin\_lang}       &\\{cmpd\_assgn}        \cr\Hrule
  406. 02&\GG    &\LS    &\LL    &\.{.DOT.}&;    &\SR    &\SlSl  &        \cr\Hrule
  407. 03&\\{stmt\_label}&\MG   &\WI    &\WL    &\NN    &\WG    &\WS    &\WV     \cr\HHrule
  408. 04&       &\WR    &       &\#     &       &\MOD   &\amp   &        \cr\Hrule
  409. 05&       &       &\ast   &+      &       &-      &       &/       \cr\Hrule
  410. 06&       &       &       &       &       &       &       &        \cr\Hrule
  411. 07&       &       &       &       &<      &=      &>      &?       \cr\Hrule
  412. 10&\Wcp   &\Wcm   &\Wcs   &\Wcv   &\Wcd   &\Wcx   &\Wca   &\Wco    \cr\Hrule
  413. 11&\Wcg   &\Wcl   &       &       &       &       &       &        \cr\Hrule
  414. 12&       &       &       &       &       &       &       &        \cr\Hrule
  415. 13&       &       &       &       &       &       &\^     &        \cr\Hrule
  416. 14&       &       &       &       &       &       &       &        \cr\Hrule
  417. 15&       &       &       &       &       &       &       &        \cr\Hrule
  418. 16&       &       &       &       &       &       &       &        \cr\Hrule
  419. 17&       &       &       &       &\OR    &\.{@@\$}&\.{@@\_},\TL&\\{param}\cr\HHrule
  420. 20&\.{L$l$}&\.{C} &\.{R}  &\.{N}  &\.{M}  &\.{X}  &       &        \cr\Hrule
  421. 21&\NP    &\NC    &\.{\#<}&\WPtr  &\CC    &       &       &
  422. \cr\Hrule
  423. 22&       &       &       &       &       &       &       &        \cr\Hrule
  424. 23&\\{constant}&\\{stringg}&\\{identifier}&\.{@@\^}&\.{@@9} &\.{@@.} &\.{@@t} &\.{@@'}  \cr\Hrule
  425. 24&\.{@@\&}&\.{@@,} &\.{@@\char'174}&\.{@@/} &\.{@@\#} &\.{@@+} &\.{@@;}& \cr\Hrule
  426. 25&\.{@@(} &\.{@@)} &\.{\ } &\\{copy\_mode}&\\{toggle\_output}&\.{@@e}&\.{@@:}&
  427. \cr\Hrule
  428. 26&       &       &\.{@@!} &       &       &\.{@@0} &\.{@@1} &\.{@@2}  \cr\Hrule
  429. 27&\.{@@f} &\.{@@\%}&       &       &\.{@@l} &\.{@@o} &\.{@@d} &\.{@@m}  \cr\Hrule
  430. 30&\.{@@\#ifdef}&\.{@@\#ifndef}&\.{@@\#if}&\.{@@\#else}&\.{@@\#elif}&\.{@@\#endif}
  431. &\.{@@\#pragma}       &\.{@@\#undef}\cr\Hrule
  432. 31&\.{@@a} &\.{@@<} &\.{@@\ }&       &       &       &       &        \cr\Hrule
  433. 32&       &       &       &       &       &       &       &        \cr\Hrule
  434. 33&       &       &       &       &       &       &       &        \cr\Hrule
  435. 34&       &       &       &       &       &       &       &
  436. \cr\Hrule
  437. 35&       &       &       &       &       &       &       &
  438. \cr\Hrule
  439. 36&       &       &       &       &       &       &       &
  440. \cr\Hrule
  441. 37&       &       &       &       &       &       &\\{begin\_cmnt0}&        \cr}
  442. \hrule width 480pt}$$
  443.  
  444.  
  445. @d ignore 0 // Control code of no interest to \WEAVE.
  446. @d verbatim OCTAL(2) // Extended |ASCII| alpha will not appear.
  447. @d force_line OCTAL(3) // Extended |ASCII| beta will not appear.
  448.  
  449. @d begin_comment0 HEX(FE) // Sent from |input_ln|.
  450. @d begin_comment1 HEX(FD)
  451. @d begin_comment OCTAL(11) // |ASCII| tab mark will not appear.
  452.  
  453. @d compound_assignment OCTAL(17) // Things like `\.{*=}'.
  454. @% @d param OCTAL(177) // |ASCII| delete will not appear.
  455.  
  456. /* Language codes. */
  457. @d L_switch OCTAL(200) // The generic language switch \.{@@L$l$}.
  458. @d begin_C OCTAL(201)
  459. @d begin_RATFOR OCTAL(202)
  460. @d begin_FORTRAN OCTAL(203)
  461. @d begin_LITERAL OCTAL(204)
  462. @d begin_TEX OCTAL(205)
  463.  
  464. @d begin_nuweb OCTAL(206) // Strictly speaking, not a language code.
  465.  
  466. /* More two-byte combinations that couldn't be fitted below printable
  467. |ASCII|. */
  468. @d dont_expand OCTAL(210) // Control code for `\.{\#!}'.
  469. @d auto_label OCTAL(211) // Control code for `\.{\#:}'.
  470. @d all_variable_args OCTAL(212) // Control code for `\.{\#.}'.
  471. @d macro_module_name OCTAL(213) // Control code for `\.{\#<\dots@@>}'.
  472. @d eq_gt OCTAL(214) // Control code for `\.{=>}'.
  473. @d colon_colon OCTAL(215) /* Control code for `\.{::}'. */
  474.  
  475. /* Control codes for \FWEB\ commands beginning with \.{@@}. */
  476.  
  477. /* The following two codes will be intercepted without confusion, because
  478. they're processed immediately after an \.{@@}, not returned from
  479. |next_control|. */
  480. @d switch_math_flag OCTAL(175)
  481. @d underline OCTAL(176)
  482.  
  483. @d xref_roman OCTAL(233) /* control code for `\.{@@\^}' */
  484. @d xref_wildcard OCTAL(234) /* control code for `\.{@@9}' */
  485. @d xref_typewriter OCTAL(235) /* control code for `\.{@@.}' */
  486. @d TeX_string OCTAL(236) /* control code for `\.{@@t}' */
  487. @d ascii_constant OCTAL(237) /* control code for `\.{@@'}' */
  488. @d join OCTAL(240) /* control code for `\.{@@\&}' */
  489. @d thin_space OCTAL(241) /* control code for `\.{@@,}' */
  490. @d math_break OCTAL(242) /* control code for `\.{@@\char'174}' */
  491. @d line_break OCTAL(243) /* control code for `\.{@@/}' */
  492.  
  493. @d big_line_break OCTAL(244) /* control code for `\.{@@\#}' */
  494. @d no_line_break OCTAL(245) /* control code for `\.{@@~' */
  495. @d pseudo_semi OCTAL(246) /* control code for `\.{@@;}' */
  496. @d defd_at OCTAL(247) // Control code for `\.['.
  497.  
  498. @d begin_meta OCTAL(250) /* Control code for |"@@("|. */
  499. @d end_meta OCTAL(251) /* Control code for |"@@)"|. */
  500.  
  501. @d macro_space OCTAL(252) /* Space token during preprocessing. */
  502. @d copy_mode OCTAL(253) /* Are we copying comments? */
  503.  
  504. @d toggle_output OCTAL(254) // Turns on and off Weave's output.
  505. @d turn_output_on OCTAL(254) // Appended to the scraps for code.
  506. @d turn_output_off OCTAL(255)
  507. @d Turn_output_on OCTAL(256)
  508. @d Turn_output_off OCTAL(257)
  509.  
  510. @d compiler_directive OCTAL(262)  // No longer used.
  511. @d Compiler_Directive OCTAL(263) /* Control code for `\.{@@?}' */
  512. @d new_output_file OCTAL(264) // Control code for `\.{@@o}'.
  513.  
  514. @d implicit_reserved OCTAL(265) // Control code for `\.{@@]}'.
  515.  
  516. @d trace OCTAL(266) /* control code for `\.{@@0}', `\.{@@1}', and `\.{@@2}' */
  517.  
  518. @d invisible_cmnt OCTAL(271) /* Control code for `\.{@@\%}' */
  519.  
  520. @d pseudo_expr OCTAL(272) /* Control code for `\.{@@e}' */
  521. @d pseudo_colon OCTAL(273) /* Control code for `\.{@@:}' */
  522.  
  523. @d begin_bp OCTAL(274) // Control code for `\.{@@\lb}'.
  524. @d insert_bp OCTAL(275) // Control code for `\.{@@b}'.
  525.  
  526. @d no_index OCTAL(276) // Control code for `\.{@@-}'.
  527. @d yes_index OCTAL(277) // Control code for `\.{@@+}'.
  528.  
  529. @d no_mac_expand OCTAL(300) // Control code for `\.{@@\!.
  530.  
  531. /* Definition section begun by codes $\ge$~|formatt|. */
  532. @d formatt OCTAL(310) /* control code for `\.{@@f}' */
  533.  
  534. @d limbo_text OCTAL(313) /* Control code for `\.{@@l}' */
  535. @d op_def OCTAL(314) /* Control code for `\.{@@v}' */
  536. @d macro_def OCTAL(315) // Control code for `\.{@@w}'.
  537.  
  538. @d definition OCTAL(320) /* control code for `\.{@@d}' */
  539. @d undefinition OCTAL(321) // Control code for `\.{@@u}'.
  540. @d WEB_definition OCTAL(322) /* Control code for `\.{@@M}' */
  541.  
  542. /* --- Preprocessor commands --- */
  543. @d m_ifdef OCTAL(330)
  544. @d m_ifndef OCTAL(331)
  545. @d m_if OCTAL(332)
  546. @d m_else OCTAL(333)
  547. @d m_elif OCTAL(334)
  548. @d m_endif OCTAL(335)
  549. @d m_for OCTAL(336)
  550. @d m_endfor OCTAL(337)
  551. @d m_pragma OCTAL(340)
  552. @d m_undef OCTAL(341)
  553.  
  554. /* --- Module names --- */
  555. @d begin_code OCTAL(350) /* control code for `\.{@@a}' */
  556. @d module_name OCTAL(351) /* control code for `\.{@@<}' */
  557.  
  558. /* --- Beginning of new module --- */
  559. @d new_module OCTAL(352) /* control code for `\.{@@\ }' and `\.{@@*}' */
  560.  
  561.  
  562. @ Control codes are converted from ASCII to \WEAVE's internal
  563. representation by means of the table |ccode|.  Codes that are used only by
  564. \FTANGLE\ get the special code~|ignore| (see \.{typedefs.hweb}; these are
  565. just skipped.  Codes that are used by neither processor are initialized
  566. to~|'0xFF'|; that can be used to trigger an error message.
  567.  
  568. @<Global...@>=
  569.  
  570. IN_STYLE eight_bits ccode[128]; 
  571.     /* Meaning of an |ASCII| char following '\.{@@}'. */
  572.  
  573. @ The control codes are set up in \.{style.web}.
  574.  
  575. @m TANGLE_ONLY(d,c) INI_CCODE(d,USED_BY_OTHER)
  576. @m WEAVE_ONLY(d,c) INI_CCODE(d,c)
  577.  
  578. @<Set ini...@>=
  579.  
  580. zero_ccodes();  // See \.{style.web}.
  581. ccode[@'/'] = line_break; /* The commenting style is also fundamental, and
  582.     for convenience the |line_break| command is also inviolate. */
  583.  
  584. @<Set the changable codes@>@;
  585. prn_codes();
  586.  
  587. @ Here are the default values for the things that are allowed to be
  588. changed.   
  589. @<Set the changable...@>= 
  590. SAME_CCODE(" \t*",new_module); // Either space, tab, or asterisk.
  591.  
  592. SAME_CCODE("aA",begin_code);
  593. SAME_CCODE("<",module_name);
  594.  
  595. SAME_CCODE("dD",definition);
  596. SAME_CCODE("uU",undefinition);
  597. SAME_CCODE("mM",WEB_definition);
  598. SAME_CCODE("fF",formatt);
  599.  
  600. WEAVE_ONLY("\001",toggle_output); // This command is for internal use only!
  601.  
  602. SAME_CCODE("'\"",ascii_constant);
  603. REASSIGNABLE("=",verbatim);
  604. WEAVE_ONLY("\\",force_line);
  605.  
  606. REASSIGNABLE("tT",TeX_string);
  607.  
  608. SAME_CCODE("L",L_switch);
  609. SAME_CCODE("cC",begin_C);
  610. SAME_CCODE("rR",begin_RATFOR);
  611. SAME_CCODE("n",begin_FORTRAN);
  612. SAME_CCODE("N",begin_nuweb);
  613. SAME_CCODE("xX",begin_TEX);
  614.  
  615. SAME_CCODE("&",join);
  616. WEAVE_ONLY("_",underline);
  617. WEAVE_ONLY("[",defd_at);
  618. WEAVE_ONLY("`]",implicit_reserved);
  619.  
  620. SAME_CCODE("%",invisible_cmnt);
  621. SAME_CCODE("?",Compiler_Directive);
  622.  
  623. WEAVE_ONLY("$",switch_math_flag);
  624.  
  625. REASSIGNABLE("^",xref_roman);
  626. REASSIGNABLE(".",xref_typewriter);
  627. REASSIGNABLE("9",xref_wildcard);
  628.  
  629. {
  630. char temp[3];
  631.  
  632. sprintf(temp,";%c",XCHR(interior_semi));
  633. WEAVE_ONLY(temp,pseudo_semi);
  634. }
  635.  
  636. WEAVE_ONLY("e",pseudo_expr);
  637. WEAVE_ONLY(":",pseudo_colon);
  638.  
  639. SAME_CCODE("l",limbo_text);
  640. SAME_CCODE("vV",op_def);
  641. SAME_CCODE("wW",macro_def);
  642.  
  643. WEAVE_ONLY(",",thin_space);
  644. WEAVE_ONLY("|",math_break);
  645. SAME_CCODE("#",big_line_break);
  646. WEAVE_ONLY("+",no_line_break);
  647.  
  648. SAME_CCODE("(",begin_meta);
  649. SAME_CCODE(")",end_meta);
  650.  
  651. SAME_CCODE("oO",new_output_file);
  652.  
  653. SAME_CCODE("{",begin_bp);
  654. TANGLE_ONLY("}bB",insert_bp);
  655. SAME_CCODE("!",no_mac_expand);
  656.  
  657. WEAVE_ONLY("-",no_index);
  658. SAME_CCODE("~",yes_index);
  659.  
  660. @<Special control codes allowed only when debugging@>@;
  661. }
  662.  
  663. @ If \WEAVE\ is compiled with debugging commands, one can write~\.{@@2},
  664. \.{@@1}, and~\.{@@0} to turn tracing fully on, partly on, and off,
  665. respectively.
  666. @<Special control codes...@>=
  667.  
  668. #if(DEBUG)
  669.     WEAVE_ONLY("012",trace);
  670. #endif /* |DEBUG| */
  671.  
  672. @ At this point |loc|~is positioned after a language command like~\.{@@c},
  673. or on the~$l$ in~\.{@@L$l$}.
  674.  
  675. @f @<Cases to set |language| and |break|@> case
  676.  
  677. @<Cases to set |language| and |break|@>=
  678.  
  679.    @<Specific language cases@>:
  680.     loc--; /* Position to letter after \.{@@}. Falls
  681. through to general case |L_switch|. */
  682.  
  683.    case L_switch:
  684.     @<Set the |language| and maybe kill rest of line@>@;
  685.     break;
  686.  
  687.    case begin_nuweb:
  688.     nuweb_mode = !NUWEB_MODE;
  689.     if(module_count == 0) 
  690.         global_params = params;
  691.     break;
  692.     
  693. @<Set the |language| and maybe kill...@>=
  694. {
  695. @<Set |language|@>@;
  696.  
  697. if(module_count == 0) 
  698.     global_params = params;
  699.  
  700. ini0_language();
  701. @<Kill rest of line; no |auto_semi|@>@;
  702. }
  703.  
  704. @ The |skip_limbo| routine is used on the first pass to skip through
  705. portions of the input that are not in any modules, i.e., that precede the
  706. first module. Language commands may be encountered at any time; these reset
  707. the current language from whatever was specified on the command line.  When
  708. the first module is found, the global language is set to the current
  709. language.
  710.  
  711. After this procedure has been called, the value of |input_has_ended| will
  712. tell whether or not a module has actually been found.
  713.  
  714. @<Part 1@>=@[
  715.  
  716. SRTN skip_limbo(VOID) 
  717. {
  718. WHILE() 
  719.     {
  720.         if (loc>limit && !get_line()) return;
  721.  
  722.         *(limit+1)=@'@@'; // Guard character.
  723.  
  724. /* Look for '@@', then skip two chars. */
  725.         while (*loc!=@'@@') loc++; 
  726.  
  727. /* |loc| now on the \.{@@}. */
  728.        if(loc++ <= limit)
  729.         switch(ccode[*loc++]) 
  730.             { /* Process any language change
  731. commands; skip any other @@~commands. */
  732.            @<Cases to set |language| and |break|@>@:@;
  733.  
  734.            case invisible_cmnt:
  735.             loc = limit + 1;
  736.             break;
  737.  
  738.            case new_module: 
  739.             return; // End of limbo section.
  740.             }
  741.     
  742. @#if(0) // Old code.
  743.         if (loc <=limit) if (ccode[*loc++]==new_module) return; 
  744. @#endif
  745.     }
  746. }
  747.  
  748. @ The |skip_TeX| routine is used on the first pass to skip through the
  749. \TeX\ code at the beginning of a module. It returns the next control code
  750. or~`\v' found in the input. A |new_module| is assumed to exist at the very
  751. end of the file.
  752.  
  753. @<Part 1@>=@[
  754.  
  755. eight_bits skip_TeX(VOID)
  756. {
  757. WHILE()
  758.     {
  759.     if (loc>limit && !get_line()) return new_module;
  760.  
  761.     *(limit+1)=@'@@'; /* Marker to curtail the scan. */
  762.  
  763.     while (*loc!=@'@@' && *loc!=@'|') loc++;
  764.  
  765.     if (*loc++ ==@'|') return @'|'; // Have hit beginning of code mode.
  766.  
  767.     if (loc<=limit) 
  768.         {
  769.         SET_CASE(*loc);
  770.         return ccode[*(loc++)];
  771.         }
  772.     }
  773.  
  774. DUMMY_RETURN(0);
  775. }
  776.  
  777. @* INPUTTING the NEXT TOKEN.
  778. As stated above, \.{WEAVE}'s most interesting lexical scanning routine is the
  779. |get_next| function that inputs the next token of \cee\ input. However,
  780. |get_next| is not especially complicated.
  781.  
  782. The result of |get_next| is either an ASCII code for some special
  783. character, or it is a special code representing a pair of characters (e.g.,
  784. `\.{!=}'), or it is the numeric value computed by the |ccode| table, or it
  785. is one of the following special codes:
  786.  
  787. \yskip\hang |identifier|: In this case the global variables |id_first| and
  788. |id_loc| will have been set to the beginning and ending-plus-one locations
  789. in the buffer, as required by the |id_lookup| routine.
  790.  
  791. \yskip\hang |string|: The string will have been copied into the array
  792. |mod_text|; |id_first| and |id_loc| are set as above (now they are
  793. pointers into |mod_text|).
  794.  
  795. \yskip\hang |constant|: The constant is copied into |mod_text|, with slight
  796. modifications; |id_first| and |id_loc| are set.
  797.  
  798. \yskip\noindent Furthermore, some of the control codes cause |get_next| to
  799. take additional actions:
  800.  
  801. \yskip\hang |xref_roman|, |xref_wildcard|, |xref_typewriter|, |TeX_string|,
  802. |verbatim|: The values of |id_first| and |id_loc| will have been set to the
  803. beginning and ending-plus-one locations in the buffer.
  804.  
  805. \yskip\hang |module_name|: In this case the global variable |cur_module| will
  806. point to the |byte_start| entry for the module name that has just been scanned.
  807.  
  808. \yskip\noindent If |get_next| sees `\.{@@\_}' it sets |xref_switch| to
  809. |def_flag| and goes on to the next token.
  810.  
  811. \yskip\noindent If |get_next| sees `\.{@@\$}' it sets |math_flag| to
  812. |!math_flag| and goes on to the next token.
  813.  
  814. @d constant OCTAL(230) /* \cee\ string or \.{WEB} precomputed string */
  815. @d stringg OCTAL(231) /* \cee\ string or \.{WEB} precomputed string */
  816. @d identifier OCTAL(232) /* \cee\ identifier or reserved word */
  817.  
  818. @<Global...@>=
  819.  
  820. EXTERN name_pointer cur_module; // Name of module just scanned.
  821. EXTERN int math_flag SET(NO);
  822. EXTERN boolean chk_end SET(YES); // Do we check for end of line?
  823. EXTERN boolean last_was_cmnt SET(NO); /* Helps with interchanging
  824.                     semicolons and comments. */
  825. EXTERN boolean lst_ampersand SET(NO); /* For continuations in
  826.         free-form syntax \Fortran-90. */
  827. EXTERN boolean eat_blank_lines SET(NO); // For Nuweb mode.
  828.  
  829. EXTERN ASCII c; // The current character for |get_next|.
  830.  
  831. @ As one might expect, |get_next| consists mostly of a big switch that
  832. branches to the various special cases that can arise.  This function has
  833. been broken into multiple function calls to |prs_TeX_code| and
  834. |prs_regular_code| in order to make it fit on personal computers.
  835.  
  836. @<Part 1@>=@[
  837.  
  838. eight_bits get_next(VOID) /* produces the next input token */
  839. {
  840. boolean terminate = NO;
  841. char terminator[2];
  842. GOTO_CODE pcode; // Return from the parsing functions.  0~means |continue|.
  843.  
  844. WHILE()
  845.     {
  846.     @<Check if we're at the id part of a preprocessor command@>;
  847.     @<Check if we're at the end of a preprocessor command@>;
  848.  
  849.     chk_end = YES;
  850.  
  851.     @<Get another line of input if necessary@>@;
  852.     @<Get next character; skip blanks and tabs@>@;
  853.  
  854. /* Handle an (effectively) empty line. (Don't move this statement upwards.) */
  855.      if(limit == cur_buffer || (at_beginning && loc > limit))  
  856.         return big_line_break; 
  857.  
  858.     switch(language)
  859.         {
  860.        case TEX:
  861.         if((pcode=prs_TeX_code()) == MORE_PARSE) 
  862.             break;
  863.         else if((int)pcode < 0) 
  864.             CONFUSION("prs_TEX_code","Negative pcode");
  865.         else 
  866.             goto found_something;
  867.  
  868.        default:
  869.         if((pcode=prs_regular_code(MORE_PARSE)) == MORE_PARSE) 
  870.             break;
  871.         else if((int)pcode < 0)
  872.             CONFUSION("prs_regular_code",
  873.                 "Negative pcode");
  874.         else 
  875.             goto found_something;
  876.         }
  877.     }
  878.  
  879. found_something:
  880.  /* We need the following stuff to handle the |INNER| parsing mode properly.
  881. (|at_beginning| doesn't correspond to physical beginning of line, so can't
  882. be reset by |get_line()|.) */
  883.     if(!preprocessing)
  884.         switch((eight_bits)pcode)
  885.             {
  886.            case begin_language:
  887.             break;
  888.  
  889.            default:
  890.             at_beginning = NO;
  891.             break;
  892.             }
  893.  
  894. return (eight_bits)pcode;
  895. }
  896.  
  897. @ Get another line of input if necessary. We raise the special flag
  898. |at_beginning| to help us with statement labels and preprocessor commands.
  899. Normally this flag is set when we get a new line.  However, it must also be
  900. set after we enter code mode by encountering vertical bars.
  901.  
  902. @<Get another line...@>=
  903.  
  904. if (loc>limit)
  905.     {
  906.     if(terminate)
  907.         {
  908.         terminator[0] = *limit; terminator[1] = *(limit+1);
  909.         }
  910.  
  911.     if(!get_line())
  912.         return(new_module);
  913.  
  914.     if(eat_blank_lines)
  915.         { /* Avoid empty stuff at end of module in Nuweb mode. */
  916.         @<Skip blank lines@>@;
  917.         eat_blank_lines = NO;
  918.         }
  919.  
  920.     if(parsing_mode == OUTER) 
  921.         at_beginning = YES; // Start of new line.
  922.  
  923.     if(terminate) 
  924.         {
  925.         *limit = terminator[0]; *(limit+1) = terminator[1];
  926.         terminate = NO;
  927.         }
  928.     }
  929. else if(parsing_mode == OUTER) at_beginning = NO;
  930.  
  931. @ In Nuweb mode, blank lines at the end of the module are significant,
  932. unless `\.{@@\%\%}' is used.  That turns on |eat_blank_lines|.
  933.  
  934. @<Skip blank lines@>=
  935. {
  936. while(loc >= limit)
  937.     if(!get_line())
  938.         {
  939.         eat_blank_lines = NO;
  940.         return(new_module);
  941.         }
  942. }
  943.  
  944. @ Here we obtain the next character, advancing~|loc| in the process.
  945. Depending on the situation, we also skip blanks and tabs.
  946.  
  947. @<Get next char...@>=
  948.  
  949. if(preprocessing) 
  950.     @<Compress string of blanks into one; if any found, return 
  951.     |macro_space|@>
  952. else
  953.     @<Skip white space at beginning of line@>@;
  954.  
  955. if(c==cont_char && loc==limit)
  956.     {
  957.     if(preprocessing || free_Fortran) loc--; /* IFFY */
  958.     else loc++;
  959.  
  960.     terminate = YES;
  961.     continue;
  962.     }
  963.  
  964. @
  965. @<Compress string of blanks...@>=
  966. {
  967. do
  968.     {
  969.     if((c=*loc++) != @' ' || c != tab_mark) 
  970.         break;
  971.     }
  972. while(loc < limit);
  973.  
  974. if(c==@' ' || c==tab_mark) 
  975.     return macro_space;
  976. }
  977.  
  978. @
  979. @<Skip white space at beg...@>=
  980. {
  981. if(language==TEX) 
  982.     c = *loc++;
  983. else
  984.     {
  985.     ASCII HUGE *loc0 = loc; // Remember starting point for nuweb mode.
  986.  
  987.     do
  988.         { /* Skip beginning white space. */
  989.         c = *loc++;
  990.         }
  991.     while(loc<=limit && (c==@' ' || c==tab_mark) );
  992.  
  993.     if(nuweb_mode)
  994.         {
  995.         if(!(c == @'@@' && *loc == @'#'))
  996.             { /* Go back to beginning. */
  997.             loc = loc0;
  998.             c = *loc++;
  999.             }
  1000.         }
  1001.     }
  1002. }
  1003.  
  1004.  
  1005. @ \TeX\ syntax differs significantly from that of the other languages.
  1006. First of all, \TeX\ comments (beginning with~'\.\%') are always short. Next,
  1007. in phase~1, we must look at the text identifier by identifier in order to make
  1008. cross-references properly.  In phase~2, however, we can absorb whole
  1009. collections of identifiers, until a comment or control code comes along.
  1010.  
  1011. In order to deal with changing category codes, we translate letters through
  1012. the array~|TeX|, which contains the most up-to-date category codes.
  1013.  
  1014. @<Part 1@>=@[
  1015. GOTO_CODE prs_TeX_code(VOID)
  1016. {
  1017. GOTO_CODE icode; // Return code from |get_control_code|.
  1018.  
  1019. if(loc>limit) 
  1020.     return @';';
  1021.  
  1022. if (c==@'@@') 
  1023.     { // The next call takes care of a branch to |mistake|.
  1024.     if((icode=get_control_code()) == GOTO_MISTAKE) 
  1025.         return prs_regular_code(GOTO_MISTAKE);
  1026.     else 
  1027.         return icode;
  1028.     }
  1029. else if(TeX[c] == TeX_comment)
  1030.     {
  1031.     long_comment = YES; // Since we may concatenate lines.
  1032.     return begin_comment;
  1033.     }
  1034. else if(c == @'|' && parsing_mode == INNER) 
  1035.     return @'|';
  1036. else 
  1037.     if(phase==1)
  1038.         {
  1039.         if(TeX[c] == TeX_escape) 
  1040.             @<Get \TeX\ identifier@>@;
  1041.         else 
  1042.             return MORE_PARSE;
  1043.         }
  1044.     else 
  1045.         @<Get \TeX\ string@>@;
  1046.  
  1047. @% return MORE_PARSE; // This means to continue to top of |get_next|.
  1048. }
  1049.  
  1050. @ If the identifier doesn't begin with a letter, it's a single-character
  1051. macro such as~`\.{\\<}'.
  1052.  
  1053. @<Get \TeX\ identifier@>=
  1054. {
  1055. id_first = id_loc = mod_text + 1;
  1056.  
  1057. *id_loc++ = *(loc-1); // The beginning backslash.
  1058.  
  1059. if(TeX[*loc] != TeX_letter)
  1060.     { /* Single-character macro, such as~`\.{\\<}'. */
  1061.     if(*loc == @'@@')
  1062.         {
  1063.         if(*(loc+1) != @'@@') ERR_PRINT(W,"You should say `\\@@@@'");
  1064.         else loc++;
  1065.         }
  1066.     *id_loc++ = *loc++; // The single character.
  1067.     }
  1068. else while(TeX[*loc] == TeX_letter)
  1069.     { /* Scan over the macro name. */
  1070.     if(*loc == @'@@')
  1071.         {
  1072.         if(*(loc+1) != @'@@') ERR_PRINT(W,"You should say `@@@@'");
  1073.         else loc++;
  1074.         }
  1075.     *id_loc++ = *loc++;
  1076.     }
  1077.  
  1078. return identifier;
  1079. }
  1080.  
  1081. @ \TeX\ strings are everything on a single line, up to a comment or, if
  1082. we're inside vertical bars, up to a terminating bar.  It looks nicer if we
  1083. leave spaces alone instead of displaying them as~`\.{\ }'.
  1084.  
  1085. @d ordinary_space 01 /* Inserted after ctrl sequences, to avoid many
  1086.             visible spcs. */
  1087.  
  1088. @<Get \TeX\ string@>=
  1089. {
  1090. loc--;
  1091. id_first = id_loc = mod_text + 1;
  1092.  
  1093. while(loc < limit)
  1094.     {
  1095.     if(*loc == @'@@')
  1096.         if(*(loc+1)==@'@@') *id_loc++ = *loc++;
  1097.         else  break; // Scan ended by control code.
  1098.  
  1099.     if(TeX[*loc] == TeX_comment) break;
  1100.     if(*loc==@'|' && parsing_mode==INNER) break; // End of internal mode.
  1101.  
  1102.     if(TeX[*loc] == TeX_escape)
  1103.         {
  1104.         if(TeX[*(loc+1)] != TeX_letter)
  1105.             { // One-character control sequence.
  1106.             if(*(loc+1) == @'@@')
  1107.                 if(*(loc+2) != @'@@') 
  1108.                     ERR_PRINT(W,"You should say \\@@@@");
  1109.                 else *id_loc++ = *loc++;
  1110.  
  1111.             *id_loc++ = *loc++;
  1112.             }
  1113.         else 
  1114.             { // Ordinary control sequence.
  1115.             do 
  1116.                 *id_loc++ = *loc++;
  1117.             while (TeX[*loc] == TeX_letter);
  1118.  
  1119.             while (loc < limit)
  1120.                 {
  1121.                 if(TeX[*loc] != TeX_space) break;
  1122.  
  1123.                 *id_loc++ = ordinary_space;
  1124.                 loc++;
  1125.                 }
  1126.                 
  1127.             continue;
  1128.             }
  1129.         }
  1130.  
  1131.     *id_loc++ = *loc++;
  1132.     }
  1133.  
  1134. return stringg;
  1135. }
  1136.     
  1137. @ Parse everything but \TeX.  
  1138. @<Part 1@>=@[
  1139.  
  1140. GOTO_CODE prs_regular_code FCN((iswitch))
  1141.     GOTO_CODE iswitch C1("")@;
  1142. {
  1143. GOTO_CODE icode; // Return code from |get_control_code|.
  1144.  
  1145. switch(iswitch)
  1146.     {
  1147.    case GOTO_MISTAKE: goto mistake;
  1148.    case GOTO_GET_IDENTIFIER: goto get_identifier;
  1149.    default: break;
  1150.     }
  1151.  
  1152. /* --- ELLIPSIS: `\.{...}' --- */
  1153. if(c==@'.' && *loc==@'.' && *(loc+1)==@'.')
  1154.     {
  1155.     ++loc;
  1156.     compress(ellipsis);
  1157.     }
  1158.  
  1159. /* --- DOT CONSTANT: `\.{.FALSE.}' --- */
  1160. else if(FORTRAN_LIKE(language) && dot_constants &&
  1161.         (c == wt_style.dot_delimiter.begin) && !isDigit(*loc))
  1162.     @<Get a dot constant@>@;
  1163.  
  1164. /* --- CONSTANT: `\.{123}', `\.{.1}', or `\.{\\135}' --- */
  1165. else if (isDigit(c) || c==@'\\' || c==@'.') @<Get a constant@>@;
  1166.  
  1167. /* --- BOZ-CONSTANT --- */
  1168. else if (in_data && Fortran88 && (*loc==@'"' || *loc==@'\'') &&
  1169.     (c==@'B' || c==@'O' || c==@'Z') ) return get_string(*loc++,c);
  1170.  
  1171. /* --- IDENTIFIER --- */
  1172. else if (is_identifier(c)) @<Get an identifier@>@;
  1173.  
  1174. /* --- STRING: `\.{"abc"}', `\.{'\\n'}', `\.{<file\_name>}' --- */
  1175.  else if (c==@'\'' || c==@'"' 
  1176.     || (sharp_include_line==YES && !in_comment &&
  1177.          (c==@'(' || (C_LIKE(language) && c==@'<') ) ))
  1178.             return get_string(c,'\0');
  1179.  
  1180. /* --- CONTROL CODE --- */
  1181. else if (c==@'@@') 
  1182.     if((icode=get_control_code()) == GOTO_MISTAKE) goto mistake;
  1183.     else return icode;
  1184.  
  1185. /* --- WHITE SPACE --- */
  1186. /* Blanks were skipped above. */
  1187. else if (c==@' ' || c==tab_mark)
  1188. @#if(0)
  1189.     if(preprocessing) /* What is this statement for? */
  1190.         {
  1191.         id_first = mod_text + 1;
  1192.         id_loc = id_first + 1;
  1193.         *id_first = c;
  1194.         return stringg;
  1195.         }
  1196.     else    /* JAK to here */
  1197. @#endif
  1198.     if(nuweb_mode)
  1199.         return c; @%(c==tab_mark ? bell : c);
  1200.     else
  1201.         return MORE_PARSE; // Ignore spaces and tabs; continue.
  1202.  
  1203. /* --- C PREPROCESSOR STATEMENT: `\.{\#include}' --- */
  1204. if (c==@'#' && at_beginning && C_LIKE(language)) @<Raise preprocessor flag@>@;
  1205.   /* If |'#'| is first character in line, it's a C~preprocessor statement. */
  1206.  
  1207. /* --- END A |@r format| STATEMENT: `\.{format(\dots);}' --- */
  1208. else if (in_format && c==@';')
  1209.     { /* End a |@r format| statement. */
  1210.     in_format = NO;
  1211.     return end_format_stmt;
  1212.     }
  1213.  
  1214. /* --- TWO-SYMBOL OPERATOR --- */
  1215. mistake: @<Compress two-symbol operator@>@;
  1216. return (eight_bits)c;
  1217. }
  1218.  
  1219. @ For FORTRAN, we allow ``dot constants'', like ~\.{.true.}\ or~\.{.or.}.
  1220. This routine scans between the dots, then looks up the identifier in a
  1221. table to see if it's valid and to get its token translation. This procedure
  1222. has a tendency to run away if an unexpected dot finds its way into the
  1223. input (either because of a syntactical mistake, or because \Weave\ is
  1224. missing the relevant rule). Thus, we limit the search to no more than
  1225. |MAX_DOT_LENGTH == 31| characters, the maximum possible length of a dot
  1226. constant. 
  1227.  
  1228. @<Get a dot constant@>=
  1229. @{
  1230. ASCII HUGE *p0;
  1231. int n;
  1232. int dcode;
  1233. ASCII dot_end = wt_style.dot_delimiter.end;
  1234.  
  1235. @b
  1236. /* At this point, |loc| is positioned to the first position after the dot. */
  1237. for(p0=loc, n=0; n<MAX_DOT_LENGTH; n++,loc++)
  1238.     if(*loc == dot_end || !isAlpha(*loc)) break; /* Found end of dot
  1239. constant, or something not allowed. */ 
  1240.  
  1241. if(*loc != dot_end) /* Didn't find end. */
  1242.     {
  1243.     loc = p0; /* Reset position back to beginning. */
  1244.     goto mistake;
  1245.     }
  1246.  
  1247. if((dcode=dot_code(dots,uppercase(p0,n),loc,dot_const)) != 0) compress(dcode);
  1248. /* Search for match in table. */
  1249.  
  1250. /* Invalid dot constant. */
  1251. loc = p0; goto mistake;
  1252. }
  1253.  
  1254. @ Because preprocessor commands do not fit in with the rest of the syntax
  1255. of C, we have to deal with them separately.  One solution [Levy] is to enclose
  1256. such commands between special markers.  Thus, when a~'\.\#' is seen as the
  1257. first character of a line, |get_next| returns a special code
  1258. \\{left\_preproc} and raises a flag |preproc|.
  1259.  
  1260. (Unfortunately, Levy's solution didn't work in certain situations, and when
  1261. the preprocessor language was installed a different method was adopted.
  1262. Thus, parts of the code are asymmetrical. This should eventually be
  1263. improved, but it was considered more important to make it work at all.)
  1264.  
  1265. @d left_preproc OCTAL(260) // Begins a preprocessor command.
  1266. @d right_preproc OCTAL(261) // Ends a preprocessor command.
  1267.  
  1268. @<Raise prep...@>= 
  1269. @{
  1270. IN_COMMON ASCII HUGE *pinclude; /* Token corresponding to |include|. */
  1271.  
  1272. @b
  1273. preprocessing = YES;
  1274. @<Check if next token is |include|@>;
  1275. return (left_preproc);
  1276. }
  1277.  
  1278. @ An additional complication is the freakish use of~'\.<' and~'\.>' to delimit
  1279. a file name in lines that start with \&{\#include}.  We must treat this file
  1280. name as a string, and use the flag |sharp_include_line| to help.
  1281.  
  1282. @<Check if next token is |include|@>=
  1283.  
  1284. /* According to ANSI, white space may be skipped at beginning of line. */
  1285. while (*loc==@' ' || *loc==@'\t') loc++;
  1286.  
  1287. if (STRNCMP(loc,pinclude,7)==0) sharp_include_line=YES;
  1288.  
  1289. @ Since the preprocessor has different reserved words than C~itself, we
  1290. include the preprocessor token with the identifier if it's first on a
  1291. preprocessor line.
  1292.  
  1293. @<Check if we're at the id...@>=
  1294.  
  1295. if(preprocessing && at_beginning) 
  1296.     {
  1297.     at_beginning = NO;
  1298.  
  1299. /* Preprocessor directives can have white space between the '\.\#' and the
  1300. name. */
  1301.     for( ; loc < limit; loc++)
  1302.         if(!(*loc==@' ' || *loc==tab_mark)) break;
  1303.  
  1304.     *(loc-1) = @'#'; /* Now we're positioned on an identifier beginning
  1305. with~|'#'|, with no intervening blanks. */
  1306.     return (eight_bits)prs_regular_code(GOTO_GET_IDENTIFIER);
  1307.     }
  1308.  
  1309. @ When we get to the end of a preprocessor line, we lower the flag and send
  1310. a code \\{right\_preproc}, unless the last character was the continuation
  1311. character'~\.\\'.
  1312.  
  1313. @<Check if we're at the end...@>=
  1314.  
  1315. chk_the_end:
  1316. if(chk_end)
  1317.  {
  1318. /* Continue to next line; also skip all lines that have continuation
  1319. character in column~1. */
  1320.   while (*loc==cont_char && loc==limit-1 && (preprocessing || free_Fortran))
  1321.     if (!get_line()) 
  1322.     return new_module; /* still in preprocessor mode */
  1323.  
  1324. /* Now we've gotten to the end of line, but it's not continued. */
  1325. if (loc>=limit)
  1326.     if(preprocessing) 
  1327.         {
  1328.         chk_end=preprocessing=sharp_include_line=NO;
  1329.         return right_preproc;
  1330.         }
  1331.     else if(Fortran88 && auto_semi && limit > cur_buffer)
  1332.         {
  1333.         loc = limit + 1;
  1334.         chk_end = NO;
  1335.         if(last_was_cmnt) 
  1336.             { // Comment has already been appended.
  1337.             last_was_cmnt = NO;
  1338.             if(lst_ampersand)
  1339.                 { // Deal with continuation before comment.
  1340.                 lst_ampersand = NO;
  1341.                 chk_end = YES;
  1342.                 if(!get_line())
  1343.                     {
  1344. ERR_PRINT(W,"Section ended in middle of Fortran-90 continuation");
  1345.                     return new_module;
  1346.                     }
  1347.                 APP_STR("\\indent");
  1348.                 goto chk_the_end;
  1349.                 }
  1350.             continue;
  1351.             }
  1352.         else return @';'; // ???
  1353.         }
  1354.  }
  1355.  
  1356. @ The following code assigns values to the combinations~\.{++}, \.{--},
  1357. \.{->}, \.{>=}, \.{<=}, \.{==}, \.{<<}, \.{>>}, \.{!=}, and~\.{\&\&}.  (For
  1358. FORTRAN, we also have~\.{//} and~\.{\^}.)  The compound assignment
  1359. operators in~C are indexed, all under the aegis of |compound_assignment|.
  1360.  
  1361. @d compress(c) if (loc++<=limit) return (eight_bits)c
  1362.  
  1363. @d COMPOUND(c,n) if(loc <= limit) {loc += n; assignment_token=c; 
  1364.         return (eight_bits)compound_assignment;}
  1365.  
  1366. @d CA_START OCTAL(100) /* The index into |op| is |CA_START + assignment_token|,
  1367. where |assignment_token| is one of the following. See |valid_op()| for
  1368. further details. */
  1369. @d plus_eq 0
  1370. @d minus_eq 01
  1371. @d star_eq 02
  1372. @d slash_eq 03
  1373. @d mod_eq 04
  1374. @d xor_eq 05
  1375. @d and_eq 06
  1376. @d or_eq 07
  1377. @d gt_gt_eq 010
  1378. @d lt_lt_eq 011
  1379. @d or_or_or 012
  1380.  
  1381. @<Glob...@>=
  1382.  
  1383. EXTERN eight_bits assignment_token; /* The particular one of the above
  1384.             compound assignment tokens. */
  1385.  
  1386. @
  1387. @<Compress two...@>=
  1388.  
  1389. switch(c) 
  1390.     {
  1391.   case (ASCII)begin_comment0:// Comment sent from FORTRAN or Ratfor |input_ln|.
  1392.     long_comment = YES;
  1393.     return begin_comment;
  1394.  
  1395.   case (ASCII)begin_comment1: // As above, but short comment.
  1396.     long_comment = NO;
  1397.     return begin_comment;
  1398.  
  1399.   case @'\\': 
  1400.     if(*loc==@'/' && !in_format && FORTRAN_LIKE(language)) 
  1401.         {
  1402.         compress(slash_slash); // `\.{\\/}' $\to$ `|@r \/|'.
  1403.         } 
  1404.     break;
  1405.  
  1406.   case @'/': 
  1407.     @<Cases for \.{\slashstar}, \.{//}, \.{/)}, and~\.{/=}@>@;
  1408.     break; 
  1409.  
  1410.   case @'(': 
  1411.     if(*loc == @'/' && !in_format) compress(left_array); 
  1412.     break;
  1413.  
  1414.   case @'+': 
  1415.     if (*loc==@'+') {compress(plus_plus); // `\.{++}' $\to$ `|++|'.
  1416.                 }
  1417.     else if(*loc==@'=') {COMPOUND(plus_eq,1); 
  1418.             // `\.{+=}' $\to$ `|+=|'. 
  1419.                 }
  1420.     break;
  1421.  
  1422.   case @'-': 
  1423.     if (*loc==@'-') {compress(minus_minus); // `\.{--}' $\to$ `|--|'.
  1424.         }
  1425.     else if (*loc==@'>') {compress(minus_gt); 
  1426.             // `\.{->}' $\to$ `|->|'. 
  1427.         } 
  1428.     else if(*loc==@'=') {COMPOUND(minus_eq,1); 
  1429.             // `\.{-=}' $\to$ `|-=|'.
  1430.         }
  1431.     break;
  1432.  
  1433.   case @'=': 
  1434.     if (*loc==@'=') {compress(eq_eq); // `\.{==}' $\to$ `|==|'.
  1435.         }
  1436.     else if(*loc==@'>') {compress(eq_gt); 
  1437.             // `\.{=>}' $\to$ `$\WPtr$'.
  1438.         } /* \FORTRAN-88's pointer assignment statement. */
  1439.     break;
  1440.  
  1441.   case @'>': 
  1442.     if (*loc==@'=') {compress(gt_eq); // `\.{>=}' $\to$ `|>=|'.
  1443.         }
  1444.     else if (*loc==@'>') 
  1445.         if(*(loc+1)==@'=') {COMPOUND(gt_gt_eq,2);
  1446.                 // `\.{>>=}' $\to$ `|>>=|'.
  1447.             }
  1448.         else {compress(gt_gt); // `\.{>>}' $\to$ `|>>|'.
  1449.             }
  1450.     break;
  1451.  
  1452.   case @'<': 
  1453.     if (*loc==@'=') {compress(lt_eq); // `\.{<=}' $\to$ `|<=|'.
  1454.         }
  1455.      else if (*loc==@'<') 
  1456.         if(*(loc+1)==@'=') 
  1457.             {COMPOUND(lt_lt_eq,2); 
  1458.                 // `\.{<<=}' $\to$ `|<<=|'. 
  1459.             }
  1460.         else {compress(lt_lt); // `\.{<<}' $\to$ `|<<|'.
  1461.             }
  1462.     else if(*loc==@'>') {compress(not_eq); 
  1463.             // `\.{<>}' $\to$ `|!=|'.
  1464.         } /* \FORTRAN-88 */
  1465.     break;
  1466.  
  1467.   case @'%': 
  1468.     if(*loc==@'=') {COMPOUND(mod_eq,1); // `\.{\%=}' $\to$ `|%=|'.
  1469.         }
  1470.     break;
  1471.  
  1472.   case @'&': 
  1473.     if (*loc==@'&') {compress(and_and); // `\.{\&\&}' $\to$ `|&&|'.
  1474.         }
  1475.     else if(*loc==@'=') 
  1476.         {
  1477.         COMPOUND(and_eq,1); // `\.{\&=}' $\to$ `|&=|'.
  1478.         }
  1479.     break;
  1480.  
  1481.   case @'|': 
  1482.     if (*loc==@'|') 
  1483.         {
  1484.         if(*(loc+1)==@'|')
  1485.             {
  1486.             COMPOUND(or_or_or,2); // `\.{\vb\vb\vb}' $\to$ `|||||'.
  1487.             }
  1488.         else compress(or_or); // `\.{\vb\vb}' $\to$ `||| |'.
  1489.         } 
  1490.     else if(*loc==@'=' && !FORTRAN_LIKE(language)) 
  1491.         {
  1492.         COMPOUND(or_eq,1); // `\.{\vertbar=}' $\to$ `||=|'. 
  1493.         }
  1494.     break;
  1495.  
  1496.   case @'!': 
  1497.     if(!in_format && (point_comments || *loc == @'!') )
  1498.         {
  1499.         if(*loc != @'!') loc--;
  1500.         long_comment = NO;
  1501.         compress(begin_comment); // \.{! Comment} or \.{!! Comment}.
  1502.         }
  1503.     else if (*loc==@'=') {compress(not_eq); // `\.{!=}' $\to$ `|!=|'.
  1504.         } 
  1505.     break;
  1506.  
  1507.   case @'*': 
  1508.     if(FORTRAN_LIKE(language) && (*loc == @'*') )
  1509.         {compress(star_star); // `\.{x**y}' $\to$ `|@r x**y|'.
  1510.         } /* Exponentiation. */
  1511.     else if(*loc==@'=') {COMPOUND(star_eq,1); // `\.{*=}' $\to$ `|*=|'.
  1512.         }
  1513.     break;
  1514.  
  1515.  case @'^': 
  1516.     if(*loc == @'^') {compress(star_star);}
  1517.     else if(FORTRAN_LIKE(language) && (loc < limit) )
  1518.          return star_star; // `\.{x\^y}' $\to$ `|@r x^y|'.
  1519.     else if(*loc==@'=') {COMPOUND(xor_eq,1); // `\.{\^=}' $\to$ `|^=|'.
  1520.         }
  1521.     break;
  1522.  
  1523.   case @':': 
  1524.     if(*loc==@':') compress(colon_colon);  // `\.{::}' $\to$ `|::|'.
  1525.     break;        
  1526.  
  1527.   case @'#': 
  1528.     @<Cases for \.{\#\#}, \.{\#!}, \.{\#:}, \.{\#.}, and~\.{\#<}@>@;
  1529.     break;
  1530.     }
  1531.  
  1532.  
  1533. @
  1534. @<Cases for \.{\slashstar}...@>=
  1535.  
  1536. if (*loc==@'*') 
  1537.     {
  1538.     long_comment = YES;
  1539.     compress(begin_comment); // \.{\slashstar\dots/starslash}
  1540.     }
  1541. else if(*loc == @'/')
  1542.     {
  1543.     if(C_LIKE(language) || language==TEX || (Cpp_comments &&
  1544. !in_format && FORTRAN_LIKE(language)))
  1545.         { /* Short comments are recognized in both~C and
  1546. \Cpp, and also in |TEX|. */
  1547.         long_comment = NO; /* \Cpp-style comment. */
  1548.         compress(begin_comment); // \.{//\dots}
  1549.         }
  1550.     else if(!in_format)
  1551.         {
  1552.         compress(slash_slash); /* Concatenation
  1553. operator~|@r \/|. Multiple slashes in |format| statements are just left
  1554. alone. */ 
  1555.         }
  1556.     }
  1557. else if(*loc == @')' && !in_format) 
  1558.     {compress(right_array); // `\.{/)}' $\to$ `$\SR$'.
  1559.     }
  1560. else if(*loc == @'=') 
  1561.     {COMPOUND(slash_eq,1); // `\.{(/}' $\to$ `$\LS$'.
  1562.     }
  1563.         
  1564. @
  1565. @<Cases for \.{\#\#}...@>=
  1566.  
  1567. switch(*loc)
  1568.     {
  1569.    case @'#':
  1570.     compress(paste); // `\.{\#\#}' $\to$ `|##|'.
  1571.     break;
  1572.  
  1573.    case @'!':
  1574.     compress(dont_expand);     // `\.{\#!}' $\to$ `|#!|'.
  1575.     break;
  1576.  
  1577.    case @':':
  1578.     compress(auto_label);     // `\.{\#:}' $\to$ `|#:|'.
  1579.     break;
  1580.  
  1581.    case @'.':
  1582.     compress(all_variable_args); // `\.{\#.}' $\to$ `|#.|'.
  1583.     break;
  1584.  
  1585.    case @'<':
  1586.     loc++;
  1587.     mac_mod_name = YES;
  1588.     @<Scan the module name and make |cur_module| point to it@>;  
  1589.     return macro_module_name;
  1590.  
  1591.    case @'\'':
  1592.    case @'"':
  1593.     if(phase == 1) loc++; // Skip over so string scanner doesn't complain.
  1594.     break;
  1595.     }
  1596.  
  1597. @ Different conventions are followed by \TeX\ and \cee\ to express octal
  1598. and hexadecimal numbers; it is reasonable to stick to each convention
  1599. withing its realm.  Thus the \cee\ part of a \.{WEB} file has octals
  1600. introduced by~\.0 and hexadecimals by~\.{0x}---e.g., \.{0377} or
  1601. \.{0xFF}---but \.{WEAVE} will print in italics or typewriter font,
  1602. respectively, and introduced by single or double quotes---e.g., |0377| or
  1603. |0xFF|.  \FWEB\ also adds binary constants, written as \.{0b10101} and
  1604. printed as |0b10101|.  In order to simplify the \TeX\ macro used to print
  1605. such constants, we replace some of the characters. (If you don't like the
  1606. way these constants look, you can easily change the macro; see
  1607. \.{fwebmac.tex}.) 
  1608.  
  1609. Notice that in this section and the next, |id_first| and |id_loc| are
  1610. pointers into the array |mod_text|, not into |cur_buffer|.
  1611.  
  1612. The next definitions correspond to the macros in \.{fwebmac.tex}.
  1613.  
  1614. @d BINARY_CODE @'&'     /* `\.{0b10101}' $\to$ `|0b10101|' */
  1615. @d OCTAL_CODE @'~'     /* `\.{0377}' $\to$ `|0377|' */
  1616. @d HEX_CODE @'`'     /* `\.{0xabc}' $\to$ `|0xabc|' */
  1617.  
  1618. @d CONSTANT_CODE @'#'    // Various kinds of constants.
  1619. @d FLOAT_CODE @'0'     // `\.{50000F}' $\to$ `|50000F|'.
  1620. @d LONG_CODE @'1'    /* `\.{50000L}' $\to$ `|50000L|' */
  1621. @d UNSIGNED_CODE @'2'    // `\.{50000U}' $\to$ `|50000U|'.
  1622. @d ULONG_CODE @'3'    // `\.{50000UL}' $\to$ `|50000UL|'.
  1623.  
  1624. @d EXP_CODE @'^'    /* `\.{(x+y)\^(a+b)}' $\to$ `|@r (x+y)^(a+b)|' */
  1625. @d HOLLERITH_CODE @'%'    /* `\.{5Hhello}' $\to$ `|@r 5Hhello|' */
  1626.  
  1627. @<Get a constant@>= 
  1628. @{
  1629. boolean decimal_point = NO;
  1630. ASCII prec_char;
  1631.  
  1632. @b
  1633. id_first = id_loc = mod_text + 1;
  1634.  
  1635. if (c==@'\\')
  1636.     { /* Probably octal---e.g., `\.{\\107}' */
  1637.     ASCII *loc0;
  1638.  
  1639.     if(*loc == @'/') goto mistake; // It's really `\.{\\/}'.
  1640.     *id_loc++ = OCTAL_CODE; // \.{WEBMAC} control code for octal.
  1641.     loc0 = loc;
  1642.     while (isOdigit(*loc)) *id_loc++ = *loc++;
  1643.     if(loc == loc0) return (eight_bits)c; // Not octal!
  1644.     }
  1645. else if (c==@'0') @<Get an octal, hex, or binary constant@>@;
  1646. else @<Get a decimal or Hollerith constant@>@;
  1647.  
  1648. @<Post-process constant@>@;
  1649.  
  1650. if(!decimal_point && at_beginning && 
  1651.     ((is_FORTRAN_(language) && !last_was_continued) ||
  1652.        (is_RATFOR_(language) && *loc == @':')))
  1653.         return stmt_label;
  1654.  
  1655. return constant;
  1656. }
  1657.  
  1658. @
  1659. @<Get an octal, hex...@>=
  1660. {
  1661.     if (*loc==@'x' || *loc==@'X') /* Hex---e.g., `\.{0xABC}' */
  1662.     {
  1663.     *id_loc++ = HEX_CODE; /* \.{WEBMAC} code for hex. */
  1664.     loc++;
  1665.         while (isXdigit(*loc)) *id_loc++ = *loc++;
  1666.     }
  1667.     else if(*loc==@'b' || *loc==@'B') /* Binary */
  1668.     {
  1669.     *id_loc++ = BINARY_CODE; /* \.{WEBMAC} code for binary. */
  1670.     loc++;
  1671.     while(isBdigit(*loc)) *id_loc++ = *loc++;
  1672.     }
  1673.     else if (isOdigit(*loc)) /* Octal---e.g., `\.{011}' */
  1674.      {
  1675.     *id_loc++ = OCTAL_CODE;
  1676.       while (isOdigit(*loc)) *id_loc++=*loc++;
  1677.     }
  1678.     else goto dec; /* decimal constant */
  1679. }
  1680.  
  1681. @ Decimal (\.{1.0e-5}) or \FORTRAN\ Hollerith constant (|@R 3Habc|).
  1682.  
  1683. @<Get a decimal...@>=
  1684. {
  1685.     if (c==@'.' && !isDigit(*loc)) goto mistake; /* Isn't a constant
  1686. like~`|.1|'. */
  1687.  
  1688. dec: 
  1689.     *id_loc++ = c;
  1690.     while (isDigit(*loc) || *loc==@'.') *id_loc++ = *loc++;
  1691. /* Optimistically, we'll include the decimal point with the constant.
  1692. However, in \Fortran\ we have to check for the possibility that it's an
  1693. integer followed by a dot constant. We do this immediately below. */
  1694.  
  1695.    decimal_point = BOOLEAN(*(loc-1) == @'.');
  1696.  
  1697.    if(FORTRAN_LIKE(language))
  1698.     if(decimal_point) /* Check for dot constant. */
  1699.         {
  1700.         if(is_dot()) /* It's an integer constant
  1701. followed by a dot constant. */
  1702.             {
  1703.             id_loc--;
  1704.             loc--;
  1705.             return constant; 
  1706.             }
  1707.         }
  1708.     else if(*loc == @'h' || *loc == @'H') @<Copy Hollerith constant@>;
  1709.  
  1710.    if(in_format) return constant;
  1711.  
  1712.     prec_char = *loc;
  1713.  
  1714.     if (prec_char==@'e' || prec_char==@'E' || (FORTRAN_LIKE(language) &&
  1715.     (prec_char==@'d' || prec_char==@'D' ||
  1716.     prec_char==@'q' || prec_char==@'Q')))
  1717.         @<Get the exponent field@>@;
  1718. }
  1719.  
  1720. @ Process the exponent part of a floating-point constant such as
  1721. \.{1.5e-10} |= 1.5e-10|.
  1722.  
  1723. @<Get the expon...@>=
  1724. {
  1725. *id_loc++ = EXP_CODE;    // Control character for WEB power of ten.
  1726. *id_loc++ = A_TO_UPPER(prec_char);
  1727.  
  1728. loc++; // Skip past the exponent character.
  1729.  
  1730. if (*loc==@'+' || *loc==@'-') *id_loc++ = *loc++;
  1731.  
  1732. while (isDigit(*loc)) *id_loc++ = *loc++;
  1733. }
  1734.  
  1735. @ Hollerith constants have the form \.{3Habc}.
  1736. @<Copy Hol...@>=
  1737. @{
  1738. int k,n;
  1739.  
  1740. @b
  1741. *id_loc = '\0'; /* Temporarily make a true terminated string. */
  1742. n = ATOI(id_first); /* Convert the string to an integer constant. */
  1743. *id_loc++ = HOLLERITH_CODE; /* Control character for WEB Hollerith macro. */
  1744. ++loc;    /* Skip the |'H'|. */
  1745.  
  1746. for(k=0; k<n; ++k) /* Copy the actual string. */
  1747.     *id_loc++ = *loc++;
  1748.  
  1749. return constant;
  1750. }
  1751.  
  1752. @ We don't yet handle correctly things like~\.{50UL}; it comes out like~|50UL|.
  1753.  
  1754. @<Post-process...@>=
  1755.  
  1756. if (C_LIKE(language))
  1757.     {
  1758.     switch(*loc)
  1759.         {
  1760.        case @'l':
  1761.        case @'L':
  1762.         *id_loc++ = CONSTANT_CODE;
  1763.         loc++;
  1764.         if(*loc == @'u' || *loc == @'U') 
  1765.             {
  1766.             *id_loc++ = ULONG_CODE;
  1767.             loc++;
  1768.             }
  1769.         else *id_loc++ = LONG_CODE;
  1770.         break;
  1771.  
  1772.        case @'u':
  1773.        case @'U':
  1774.         *id_loc++ = CONSTANT_CODE;
  1775.         loc++;
  1776.         if(*loc == @'l' || *loc == @'L') 
  1777.             {
  1778.             *id_loc++ = ULONG_CODE;
  1779.             loc++;
  1780.             }
  1781.         else *id_loc++ = UNSIGNED_CODE;
  1782.         break;
  1783.  
  1784.        case @'f':
  1785.        case @'F':
  1786.         *id_loc++ = CONSTANT_CODE;
  1787.         *id_loc++ = FLOAT_CODE;
  1788.         loc++;
  1789.         break;
  1790.         }
  1791.     }
  1792. else if(Fortran88) @<Absorb optional kind-param@>@;
  1793.  
  1794. @ In \Fortran-90, there can be optional kind parameters after a constant,
  1795. started off by an underscore. Example: |@r 50_4|. 
  1796. @<Absorb optional kind-param@>=
  1797. {
  1798. if(*loc == @'_')
  1799.     while(is_kind(*loc))
  1800.         *id_loc++ = *loc++;
  1801. }
  1802.  
  1803. @ Code strings and character constants, delimited by double and single
  1804. quotes, respectively, can contain newlines or instances of their own
  1805. delimiters if they are protected by a backslash (for~C) or if the delimiter
  1806. is repeated (for \FORTRAN).  We follow this convention, but do not allow
  1807. the string to be longer than |longest_name|.  Special codes are inserted
  1808. every |NBREAK| characters so that \TeX\ can break the strings.  (The count
  1809. is restarted after commas, which are also treated as discretionary breaks.)
  1810.  
  1811. @d discretionary_break OCTAL(177)
  1812. @d NBREAK 25 // \bf Put into style file?
  1813.  
  1814. @<Glob...@>=
  1815.  
  1816. EXTERN boolean insert_breaks SET(YES); /* No breaks inserted during limbo
  1817.             text processing. */
  1818.  
  1819. @ Here we absorb a string.  Examples:  \.{"abc"}, \.{'\\n'}, or
  1820. \.{<file\_name>}. 
  1821.  
  1822. @<Part 1@>=@[
  1823.  
  1824. eight_bits get_string FCN((c,boz))
  1825.     ASCII c C0("What started the string")@;
  1826.     ASCII boz C1("The boz character, or 0.")@;
  1827. {
  1828. ASCII delim = c; /* what started the string */
  1829. ASCII right_delim = c;
  1830. int level,kount;
  1831. boolean equal_delims;
  1832.  
  1833.   id_first = mod_text + 1;
  1834.   id_loc = mod_text;
  1835.  
  1836. /* ???? */
  1837.   if (delim==@'\'' && *(loc-2)==@'@@') {*++id_loc=@'@@'; *++id_loc=@'@@';}
  1838.   *++id_loc=delim;
  1839.  
  1840. @<Determine the right matching delimiter@>@;
  1841.  
  1842. kount = 0; /* How far since last discretionary line break command. */
  1843.  
  1844. WHILE()
  1845. { /* Scan for end of string. */
  1846.     if (loc>=limit) @<Check for continued string@>@;
  1847.  
  1848.     if ((c=*loc++)==delim) @<Handle left-hand delimiter@>@;
  1849.  
  1850.   if(c==right_delim)
  1851.     if(--level == 0)
  1852.         {
  1853.           if (++id_loc<=mod_end) *id_loc=c;
  1854.          break; /* Found end of string for unequal delims. */
  1855.         }
  1856.  
  1857. /* Handle a final backslash. */
  1858.     if ((c==cont_char) && 
  1859.          (C_LIKE(language) || (is_FORTRAN_(language) && free_form_input)))
  1860.     if (loc>=limit) continue;
  1861.       else if (++id_loc<=mod_end) 
  1862.         {
  1863.             *id_loc = c; c=*loc++;
  1864.             }
  1865.  
  1866. /* Store the character. */
  1867.     if (++id_loc<=mod_end) *id_loc=c;
  1868.  
  1869.     @<Insert discretionary line-break commands@>@;
  1870.   } /* End of \&{while}. */
  1871.  
  1872.   if (id_loc>=mod_end) 
  1873.     {
  1874.     SET_COLOR(error);
  1875.     printf("\n! String too long: ");
  1876. @.String too long@>
  1877.     ASCII_write(mod_text+1,25);
  1878.     printf("..."); mark_error;
  1879.       }
  1880.  
  1881.   id_loc++;
  1882.  
  1883. @<Check for boz constant@>@;
  1884.  
  1885. return stringg;
  1886. }
  1887.  
  1888. @
  1889. @<Determine the right...@>=
  1890. {
  1891. switch(delim)
  1892.     {
  1893.    case @'<':
  1894.     right_delim=@'>'; // for file names in |#include| lines.
  1895.     break;
  1896.  
  1897.    case @'(':
  1898.      right_delim = @')'; // For m4 \&{include} or related functions.
  1899.     sharp_include_line = NO;
  1900.     break;
  1901.  
  1902.    case @'[':
  1903.     right_delim = @']'; // For auto insertions in macro definitions.
  1904.     break;
  1905.     }
  1906.  
  1907. level = 1; // For searching for balanced delimiters.
  1908.  
  1909. equal_delims = BOOLEAN(right_delim==delim);
  1910. }
  1911.  
  1912. @
  1913. @<Check for continued string@>=
  1914. {
  1915.       if( (equal_delims || chk_ifelse) && *(limit-1)!=cont_char) 
  1916.         {
  1917.            err_print(W,"String beginning with '\\%c' didn't end",XCHR(delim)); 
  1918.             loc=limit; break;
  1919. @.String didn't end@>
  1920.             }
  1921.  
  1922.       if(!get_line())
  1923.         {
  1924.             err_print(W,"Input ended in middle of string beginning with \
  1925. '\\%c'",XCHR(delim)); 
  1926.             loc=cur_buffer;
  1927.         break; 
  1928. @.Input ended in middle of string@>
  1929.           }
  1930.     else
  1931.        {
  1932. /* Now the continuation of the string is in the buffer.  If appropriate,
  1933. skip over beginning white space and backslash. */
  1934.     if(bslash_continued_strings)
  1935.         {
  1936.         for(; loc < limit; loc++)
  1937.             if(*loc != @' ' && *loc != tab_mark) break;
  1938.  
  1939.         if(*loc == cont_char) loc++; /* Move past the backslash. */
  1940.         else err_print(W,"Inserted '\\%c' at beginning of continued \
  1941. string",XCHR(cont_char));
  1942.         }
  1943.         }
  1944.  }
  1945.  
  1946. @
  1947. @<Handle left-hand delim...@>=
  1948. {
  1949. level++;
  1950.  
  1951. if (++id_loc<=mod_end) *id_loc=c;
  1952.  
  1953. if(!equal_delims) continue;
  1954.  
  1955. if(FORTRAN_LIKE(language) && (*loc == delim) ) 
  1956.     ++loc; /* Copy over repeated delimiter. */
  1957. else  break;  /* Found end of string. */
  1958. }    
  1959.  
  1960. @ Insert discretionary line-break command  every |NBREAK|
  1961. characters. Since the string macro also inserts discretionary breaks after
  1962. commas, we reset the counter to~0 after a comma. As one annoyance, we don't
  1963. want to insert a break immediately after an~`\.{@@}', because the output
  1964. routines would otherwise get confused.
  1965. @<Insert discretionary line-break...@>=
  1966.  
  1967. if(insert_breaks)
  1968.     if(c == @',') kount = 0;
  1969.     else if(++kount >= NBREAK && c != @'@@' && ++id_loc<=mod_end)
  1970.             {
  1971.             kount = 0;
  1972.             *id_loc = discretionary_break;
  1973.             }
  1974.  
  1975. @ In \Fortran-90, we have \It{boz-constants}---binary, octal, or
  1976. hexadecimal constants that look like~`\.{B'011'}', `\.{O'077'}',
  1977. or~`\.{Z'FF'}'. (The single quotes may be replaced by double quotes.)
  1978. These constants may appear only in |@r data| statements.
  1979.  
  1980. @<Check for boz...@>=
  1981. {
  1982. if(FORTRAN_LIKE(language))
  1983.     if(boz)
  1984.         @<Handle boz constant@>@;
  1985.     else
  1986.         @<Handle VAX extensions of hex or octal constants@>@;
  1987. }
  1988.  
  1989. @ At this point we already know we're dealing with a boz constant.
  1990. @<Handle boz...@>=
  1991. {
  1992. switch(boz)
  1993.     {
  1994.     case @'B':
  1995.         *id_first = BINARY_CODE;
  1996.         break;
  1997.  
  1998.     case @'O':
  1999.         *id_first = OCTAL_CODE;
  2000.         break;
  2001.  
  2002.     case @'Z':
  2003.         *id_first = HEX_CODE;
  2004.         break;
  2005.     }
  2006.         
  2007. id_loc--;
  2008. return constant;
  2009. }
  2010.  
  2011. @ Handle the VAX extensions of hex or octal
  2012. constants---e.g., \.{'abc'X} or \.{'123'O}.
  2013. @<Handle VAX exten...@>=
  2014. if(*loc==@'X' || *loc==@'x')
  2015.     {
  2016.     *id_first = HEX_CODE;    /* Overwrite opening delimiter. */
  2017.     @<Finish VAX hex/octal constant.@>@;
  2018.     }
  2019. else if(*loc==@'O' || *loc==@'o')
  2020.     {
  2021.     *id_first = OCTAL_CODE; /* Octal */
  2022.     @<Finish VAX hex...@>@;
  2023.     }
  2024. }
  2025.  
  2026. @<Finish VAX hex...@>=
  2027.  
  2028.     loc++;    /* Skip the ending signifier. */
  2029.     id_loc--; /* Forget closing delimiter. */
  2030.     return constant;
  2031.  
  2032. @
  2033. @<Glob...@>=
  2034.  
  2035. EXTERN boolean doing_cdir SET(NO);
  2036.  
  2037. @ After an \.{@@}~sign has been scanned, the next character tells us
  2038. whether there is more work to do.  Note that lower- and upper-case control
  2039. codes are generally treated as variants of the same fundamental code; to
  2040. distinguish them, we set the |upper_case_code| flag.  When the code is in
  2041. upper case, it does not automatically issue an implicit~\.{@@[}, for example.
  2042.  
  2043. @<Part 1@>=@[
  2044. GOTO_CODE get_control_code(VOID)
  2045. {
  2046. eight_bits cc; /* The |ccode| value. */
  2047.  
  2048. @b
  2049. c = *loc++;
  2050. SET_CASE(c); // Set the |upper_case_code| flag.
  2051.  
  2052. /* Deflect a verbatim comment beginning with `\.{@@\slashstar}'. */
  2053. if( (c==@'/' && (*loc==@'*' || *loc==@'/')) || 
  2054.         c==(ASCII)begin_comment0 || c==(ASCII)begin_comment1)
  2055.     return GOTO_MISTAKE; 
  2056.  
  2057. switch(cc = ccode[c]) 
  2058.     {
  2059.    case no_index:
  2060.     index_flag = NO;
  2061.     return MORE_PARSE;
  2062.  
  2063.    case yes_index:
  2064.     INDEX_SHORT;
  2065.     return MORE_PARSE;
  2066.  
  2067.     case defd_at:
  2068.     if(mark_defined.generic_name)
  2069.         {
  2070.         defd_switch = YES; // `\.{@@[}'.
  2071.         defd_type = GENERIC_NAME;
  2072.         } //   \bf NOTE: Falls through.
  2073.  
  2074.     case underline: 
  2075.     xref_switch = def_flag; // `\.{@@\_}'
  2076.     return MORE_PARSE;
  2077.  
  2078.    case implicit_reserved:
  2079.     if(mark_defined.imp_reserved_name)
  2080.         {
  2081.         typd_switch = defd_switch = YES; // `\.{@@`}'.
  2082.         defd_type = IMPLICIT_RESERVED;
  2083.         xref_switch = def_flag;
  2084.         }
  2085.     return MORE_PARSE;
  2086.  
  2087.     case switch_math_flag: math_flag=!math_flag;  // `\.{@@\$}'
  2088.     return MORE_PARSE;
  2089.  
  2090. #ifdef DEBUG
  2091.     case trace: tracing=c-@'0'; // `\.{@@0}', `\.{@@1}', `\.{@@2}'
  2092.     return MORE_PARSE;
  2093. #endif /* |DEBUG| */
  2094.  
  2095. /* For language switches, we set the |language|, then
  2096. send back a single code |begin_language|. When we process this, we'll then
  2097. append another 8-bit code with the language number itself. */
  2098.  
  2099.    @<Specific language cases@>:
  2100.     loc--; // Falls through to general case below.
  2101.  
  2102.    case L_switch:
  2103.     {
  2104.     @<Set the |language|...@>@;
  2105.     return begin_language; // `\.{@@L$l$}'
  2106.     }
  2107.  
  2108.    case begin_nuweb:
  2109.     ERR_PRINT(W,"@@N ignored; must appear before beginning of code part");
  2110.     return MORE_PARSE;
  2111.  
  2112.     case xref_roman: case xref_wildcard: case xref_typewriter:
  2113.     case TeX_string: @<Scan to the next \.{@@>}@>@; /* `\.{@@\^\dots@@>}',
  2114. `\.{@@9\dots@@>}', `\.{@@.\dots@@>}', and `\.{@@t\dots@@>}'. */
  2115.  
  2116.     case module_name: 
  2117.     mac_mod_name = NO; // Used as a flag for macro processing.
  2118.     @<Scan the module name and make |cur_module| point to it@>@;
  2119.     return module_name; // `\.{@@<\dots@@>}'
  2120.  
  2121.     case new_output_file:
  2122.     @<Scan the output file name@>@;
  2123.     return cc;
  2124.  
  2125.     case invisible_cmnt:
  2126.     if(*loc == @'%')
  2127.         eat_blank_lines = YES;
  2128.     loc = limit + 1; // Skip the line.
  2129.     return MORE_PARSE; // `\.{@@\%}
  2130.  
  2131.     case compiler_directive:
  2132.     case Compiler_Directive:
  2133.     long_comment = NO;
  2134.     doing_cdir = YES;
  2135.     return begin_comment; // `\.{@@!}' or `\.{@@?}'
  2136.  
  2137.     case verbatim: @<Scan a verbatim string@>@; // `\.{@@=\dots@@>}'
  2138.  
  2139.     case ascii_constant: return get_string(c,'\0'); // `\.{@@'\dots'}'
  2140.  
  2141.     case big_line_break: // `\.{@@\#}'
  2142.     if(loc >= limit) return cc;
  2143.  
  2144.     @<Process possible pre...@>; // In \.{typedefs.web}.
  2145.     return cc;
  2146.  
  2147.     case begin_bp:
  2148.     return @'{'; // Ought to improve this, to mark the debugging locations.
  2149.  
  2150.     case USED_BY_NEITHER:
  2151.     if(phase==1) 
  2152.         err_print(W,"Invalid `@@%c' ignored",XCHR(c));
  2153.  
  2154.     return ignore;
  2155.  
  2156.     default: return cc;
  2157.     }
  2158. }
  2159.  
  2160. @ The occurrence of a module name sets |xref_switch| to zero, because the
  2161. module name might (for example) follow \&{int}.
  2162.  
  2163. @<Scan the module name...@>= 
  2164. @{
  2165. ASCII HUGE *k; // Pointer into |mod_text|.
  2166. static ASCII ell[] = @"...";
  2167. static ASCII bad_mod_name[] = @"!!! {\\it Incompatible} !!!";
  2168.  
  2169. @b
  2170. @<Put module name into |mod_text|@>@;
  2171.  
  2172. if (k-mod_text > 3 && STRNCMP(k-2,ell,3)==0)
  2173.     cur_module = prefix_lookup(mod_text+1,k-3); 
  2174. else cur_module = mod_lookup(mod_text+1,k);
  2175.  
  2176. if(!cur_module) 
  2177.       cur_module = mod_lookup(bad_mod_name,bad_mod_name+STRLEN(bad_mod_name)); 
  2178.  
  2179. if(cur_module)
  2180.     {
  2181. @#if 0
  2182.     language = (LANGUAGE)cur_module->Language;
  2183. @#endif
  2184.     params = cur_module->mod_info->params;// Restore state for this module.
  2185.     frz_params();
  2186.     }
  2187.  
  2188. xref_switch = NO; 
  2189.  
  2190. /* The actual return value can be either |module_name| or
  2191. |macro_module_name| and is put in explicitly right after the use of this
  2192. module in the code. */ 
  2193. }
  2194.  
  2195. @ Module names are placed into the |mod_text| array with consecutive
  2196. spaces, tabs, and carriage-returns replaced by single spaces. There will be
  2197. no spaces at the beginning or the end. (We set |mod_text[0]=' '| to
  2198. facilitate this, since the |mod_lookup| routine uses |mod_text[1]| as the
  2199. first character of the name.)
  2200.  
  2201. @<Set init...@>=
  2202.  
  2203. mod_text[0] = @' ';
  2204.  
  2205. @ Here we copy the text of the module name, stripping off white space from
  2206. the front and back.  Also, we convert any real semicolons into interior
  2207. semis.  This helps out with language switches between \Fortran\ and~C, for
  2208. example.  If the global language were~C, then a module name that should be
  2209. read in \Fortran\ will be first be absorbed in~C because the parser doesn't
  2210. know yet which language it will be.
  2211.  
  2212. @<Put module name...@>=
  2213. {
  2214. int mlevel = 1; // For nested module names.
  2215.  
  2216. k = mod_text;
  2217.  
  2218. WHILE()
  2219.     {
  2220.     if (loc>limit && !get_line())
  2221.         {
  2222.         ERR_PRINT(W,"Input ended in section name");
  2223. @.Input ended in section name@>
  2224.         loc=cur_buffer+1; break;
  2225.         }
  2226.  
  2227.       c = *loc;
  2228.       @<If end of name, |break|@>;
  2229.       loc++; 
  2230.  
  2231.     if (k<mod_end) k++;
  2232.  
  2233.     switch(c)
  2234.         {
  2235.        case @' ':
  2236.        case tab_mark:
  2237.         c=@' '; if (*(k-1)==@' ') k--; // Compress white space.
  2238.         break;
  2239.  
  2240.        case @';':
  2241.         c = interior_semi;
  2242.         break;
  2243.         }
  2244.  
  2245.     *k = c;
  2246.     }
  2247.  
  2248. if (k>=mod_end) 
  2249.     {
  2250.   SET_COLOR(warning);
  2251.   printf("\n! Section name too long: ");
  2252. @.Section name too long@>
  2253.   ASCII_write(mod_text+1,25);
  2254.   printf("..."); mark_harmless;
  2255.     }
  2256.  
  2257. if (*k==@' ' && k>mod_text) k--; // Trailing blanks.
  2258. }
  2259.  
  2260. @<If end of name,...@>=
  2261.  
  2262. if (c==@'@@') 
  2263.     {
  2264.     c = *(loc+1);
  2265.  
  2266.     if (c==@'>')
  2267.         {
  2268.         if(--mlevel == 0)
  2269.             {
  2270.             loc+=2; break;
  2271.             }
  2272.         }
  2273.     else if(c==@'<') mlevel++;
  2274.  
  2275.       if (ccode[c]==new_module) 
  2276.         {
  2277.         ERR_PRINT(W,"Section name didn't end"); break;
  2278. @.Section name didn't end@>
  2279.         }
  2280.  
  2281.       *(++k) = @'@@'; loc++; // Now |c==*loc| again.
  2282.     }
  2283.  
  2284. @ This fragment is used for skipping over control text, such as
  2285. `\.{@@t\dots@@>}'. 
  2286.  
  2287. @<Scan to the next...@>= 
  2288. {
  2289. cc = ccode[*(loc-1)]; /* Is this statement redundant? */
  2290. id_first=loc; *(limit+1)=@'@@';
  2291.  
  2292. while (*loc!=@'@@') loc++;
  2293.  
  2294. id_loc=loc;
  2295.  
  2296. if (loc++>limit) 
  2297.     {
  2298.     ERR_PRINT(W,"Control text didn't end"); loc=limit; return cc;
  2299. @.Control text didn't end@>
  2300.     }
  2301.  
  2302. if (*loc++!=@'>') ERR_PRINT(W,"Control codes are forbidden in control text");
  2303. @.Control codes are forbidden...@>
  2304.  
  2305. return cc;
  2306. }
  2307.  
  2308. @ At the present point in the program we have |*(loc-1)=verbatim|; we set
  2309. |id_first| to the beginning of the string itself, and |id_loc| to its
  2310. ending-plus-one location in the buffer.  We also set~|loc| to the position
  2311. just after the ending delimiter.
  2312.  
  2313. @<Scan a verbatim string@>= 
  2314. {
  2315. id_first=loc++; 
  2316.  
  2317. *(limit+1)=@'@@'; *(limit+2)=@'>';
  2318.  
  2319. while (*loc!=@'@@' || *(loc+1)!=@'>') loc++;
  2320.  
  2321. if (loc>=limit) ERR_PRINT(W,"Verbatim string didn't end");
  2322. @.Verbatim string didn't end@>
  2323.  
  2324. id_loc=loc; loc+=2;
  2325.  
  2326. return (verbatim);
  2327. }
  2328.  
  2329. @* PHASE ONE PROCESSING.
  2330. We now have accumulated enough subroutines to make it possible to carry out
  2331. \.{WEAVE}'s first pass over the source file. If everything works right,
  2332. both phase one and phase two of \.{WEAVE} will assign the same numbers to
  2333. modules, and these numbers will agree with what \.{TANGLE} does.
  2334.  
  2335. The global variable |next_control| often contains the most recent output of
  2336. |get_next|; in interesting cases, this will be the control code that ended
  2337. a module or part of a module.
  2338.  
  2339. @<Global...@>=
  2340.  
  2341. EXTERN eight_bits next_control; /* control code waiting to be acting upon */
  2342.  
  2343. @ The overall processing strategy in phase one has the following
  2344. straightforward outline.
  2345.  
  2346. @<Part 2@>=@[
  2347.  
  2348. SRTN phase1(VOID) 
  2349. {
  2350. LANGUAGE language0=language;
  2351.  
  2352. phase = 1; 
  2353. the_part = LIMBO;
  2354.  
  2355. rst_input(); 
  2356. reading(web_file_name,(boolean)(tex_file==stdout));
  2357. module_count = 0;
  2358. skip_limbo(); // Skip stuff before any module (but process language commands).
  2359. change_exists = NO;
  2360.  
  2361. /* Remember the language to put into force at the beginning of each module.
  2362.   |language| may have been set from the command line, by default (nothing on
  2363.   the command line), or by explicit~\.{@@c}, \.{@@r}, \.{@@n},
  2364. or~\.{@@L$l$} commands  during the limbo phase. */
  2365. chk_override(language0);
  2366. fin_language(); /* Make sure all flags are initialized properly. */
  2367. global_params = params;
  2368.  
  2369. while (!input_has_ended)
  2370.   @<Store cross-reference data for the current module@>;
  2371.  
  2372. chngd_module[module_count]=change_exists;
  2373.   /* the index changes if anything does */
  2374.  
  2375. @<Print error messages about unused or undefined module names@>;
  2376. }
  2377.  
  2378. @<Store cross-reference data...@>=
  2379. {
  2380. the_part = TEX_;
  2381.  
  2382.   if (++module_count==(sixteen_bits)max_modules) 
  2383.     OVERFLW("section numbers",ABBREV(max_modules)); 
  2384.  
  2385.   chngd_module[module_count]=NO; // It will become |YES| if any line changes.
  2386.  
  2387.     progress();
  2388.  
  2389. /* All modules start off in the global language. */
  2390. params = global_params;
  2391. frz_params();
  2392.  
  2393.   @<Store cross-references in the \TeX\ part of a module@>;
  2394.   @<Store cross-references in the definition part of a module@>;
  2395.   @<Store cross-references in the \cee\ part of a module@>;
  2396.  
  2397.   if(chngd_module[module_count]) 
  2398.     change_exists=YES;
  2399.  
  2400. typd_switch = defd_switch = NO; // Don't propagate beyond one module.
  2401. }
  2402.  
  2403. @ The |C_xref| subroutine stores references to identifiers in \cee\ text
  2404. material beginning with the current value of |next_control| and continuing
  2405. until |next_control| is~`\.\{' or~`\v', or until the next ``milestone'' is
  2406. passed (i.e., |next_control>=formatt|). If |next_control>=formatt| when
  2407. |C_xref| is called, nothing will happen; but if |next_control="|"| upon
  2408. entry, the procedure assumes that this is the~`\v' preceding \cee\ text
  2409. that is to be processed.
  2410.  
  2411. The program uses the fact that our internal code numbers satisfy the
  2412. relations |xref_roman=identifier+roman| and |xref_wildcard=identifier
  2413. +wildcard| and |xref_typewriter=identifier+typewriter| and |normal=0|.
  2414.  
  2415. @<Part 2@>=@[
  2416.  
  2417. SRTN C_xref FCN((part0,mode0))
  2418.     PART part0 C0("")@;
  2419.     PARSING_MODE mode0 C1("")@;
  2420. {
  2421. PARAMS outer_params;
  2422. name_pointer p; /* a referenced name */
  2423.  
  2424. parsing_mode = mode0;
  2425.  
  2426. if(parsing_mode == INNER)
  2427.     outer_params = params; /* Store whole structure. */
  2428.  
  2429. while (next_control<formatt) 
  2430.     {
  2431.     switch(next_control)
  2432.         {
  2433.          case begin_language:
  2434. @<Handle a possible language switch in the middle of the module@>@;
  2435.         break;
  2436.  
  2437.        case toggle_output:
  2438. @%        @<Toggle output@>@;
  2439.         break;
  2440.  
  2441.        case begin_meta:
  2442.         @<Skip over meta-comment@>@;
  2443.         break;
  2444.  
  2445.        case identifier:
  2446.        case xref_roman:
  2447.        case xref_wildcard:
  2448.        case xref_typewriter:
  2449.         p=id_lookup(id_first,id_loc,
  2450.             (eight_bits)(next_control-identifier));
  2451.  
  2452.         new_xref(part0,p); 
  2453.  
  2454.         if(part0 == DEFINITION) 
  2455.             defd_switch = NO; /* Prevent the implicit~\.{@@[}
  2456. from propagating beyond the first identifier. */ 
  2457.  
  2458.         if(next_control==identifier && p->ilk == typedef_like
  2459.                 && C_LIKE(language)
  2460.                 && parsing_mode == OUTER)
  2461.             @<Mark \&{typedef} variable@>@;
  2462.         break;
  2463.         }
  2464.  
  2465.     next_control=get_next();
  2466.  
  2467.     if ( next_control==@'|' || next_control==begin_comment) break;
  2468.     }
  2469.  
  2470. end_xref:
  2471.   if(parsing_mode==INNER)
  2472.     {
  2473.     params = outer_params;
  2474.     frz_params();
  2475.     parsing_mode = OUTER;
  2476.     }
  2477. }
  2478.  
  2479. @
  2480. @<Skip over meta-comment@>=
  2481. {
  2482. WHILE()
  2483.     {
  2484.     if(!get_line()) 
  2485.         {
  2486.         ERR_PRINT(W,"Input ended during meta-comment");
  2487.         break;
  2488.         }
  2489.         
  2490.     if(*loc == @'@@')
  2491.         switch(*(loc+1))
  2492.             {
  2493.            case @')':
  2494.             get_line();
  2495.  
  2496.            case @'*':
  2497.            case @' ':
  2498.             goto done_meta;
  2499.             }
  2500.     }
  2501.  
  2502. done_meta:;
  2503. }
  2504.  
  2505. @ For the forward-referencing facility, we need to format the variable of a
  2506. \&{typedef} during phase~1.  We mark the first variable we come to that isn't
  2507. reserved and isn't enclosed by braces.  (We must format identifiers even if
  2508. they're inside braces.)
  2509. @<Mark \&{typedef} variable@>=
  2510. {
  2511. int brace_level = 0;
  2512.  
  2513. /* First, we scan over a possible |struct|. */
  2514. while((next_control=get_next()) == identifier)
  2515.     if((p=id_lookup(id_first,id_loc,0))->ilk != struct_like) 
  2516.         {
  2517.         new_xref(part0,p); // Structure name: |typedef struct s|.
  2518.         next_control = get_next(); // Don't repeat the structure name.
  2519.         break;
  2520.         }
  2521.  
  2522. while(next_control <=module_name)
  2523.     {
  2524.     switch(next_control)
  2525.         {
  2526.        case @'{':
  2527.         brace_level++;
  2528.         break;
  2529.  
  2530.        case @'}':
  2531.         if(brace_level-- == 0) 
  2532.             {
  2533.             ERR_PRINT(W,"Extra '}' in typedef");
  2534.             goto done;
  2535.             }
  2536.         break;
  2537.  
  2538.        case identifier:
  2539.         p = id_lookup(id_first,id_loc,0);
  2540.         if(brace_level == 0 && mark_defined.typedef_name)
  2541.             {
  2542.             typd_switch = defd_switch = YES;
  2543.             defd_type = TYPEDEF_NAME;
  2544.             }
  2545.         new_xref(part0,p);
  2546.         break;
  2547.  
  2548.        case formatt:
  2549.        case limbo_text:
  2550.        case op_def:
  2551.        case macro_def:
  2552.        case definition:
  2553.        case undefinition:
  2554.        case WEB_definition:
  2555.        case begin_code:
  2556.        case new_output_file:
  2557.         ERR_PRINT(W,"You can't do that inside a typedef");
  2558.         break;
  2559.  
  2560.        case module_name:
  2561.         if(cur_module) new_mod_xref(cur_module);
  2562.         next_control = get_next();
  2563.         if(next_control == @'=')
  2564.             {
  2565.             ERR_PRINT(W,"'=' not allowed after @@<...@@> \
  2566. inside typedef; check typedef syntax.  Inserted ';'");
  2567.             next_control = @';';
  2568.             }
  2569.         continue;
  2570.  
  2571.        case @';':
  2572.         if(brace_level == 0) goto done; // End of |typedef|.
  2573.         break;
  2574.  
  2575.        case begin_comment:
  2576.         @<Handle a comment@>@;
  2577.         break;
  2578.         }
  2579.  
  2580.     next_control = get_next();
  2581.     }
  2582.  
  2583. done: 
  2584.   defd_switch = typd_switch = NO; // Just in case we screwed up.
  2585.  
  2586.   if(next_control == new_module)
  2587.     {
  2588.     ERR_PRINT(W,"Module ended during typedef");
  2589.     goto end_xref;
  2590.     }
  2591. }
  2592.  
  2593. @ The |language| has already been set inside |get_next()| when we get to here.
  2594.  
  2595. @<Handle a possible language switch...@>=
  2596.  
  2597. switch(language)
  2598.     {
  2599.     case NO_LANGUAGE:
  2600.         CONFUSION("handle possible language switch",
  2601.             "Language isn't defined");
  2602.  
  2603.     case FORTRAN:
  2604.     case FORTRAN_90:
  2605.     case RATFOR:
  2606.     case RATFOR_90:
  2607.         if(mode0 == OUTER && !free_form_input) 
  2608.             @<Set up column mode@>@;
  2609.         break;
  2610.  
  2611.     case TEX:
  2612.         if(mode0 == OUTER) @<Set up col...@>@;
  2613.         break;
  2614.  
  2615.     case C:
  2616.     case C_PLUS_PLUS:
  2617.     case LITERAL:
  2618.         column_mode = NO;
  2619.         break;
  2620.  
  2621.     case NUWEB_OFF:
  2622.     case NUWEB_ON:
  2623.         CONFUSION("handle possible language switch","Invalid langage");
  2624.     }
  2625.  
  2626.  
  2627. @ The |outr_xref| subroutine is like |C_xref| but it begins with
  2628. |next_control!='|'| and ends with |next_control>=formatt|. Thus, it handles
  2629. \cee\ text with embedded comments.
  2630.  
  2631. @<Part 2@>=@[
  2632.  
  2633. SRTN outr_xref FCN((part0)) /* extension of |C_xref| */
  2634.     PART part0 C1("")@;
  2635. {
  2636. while (next_control<formatt)
  2637.     if (next_control!=begin_comment) 
  2638.         C_xref(part0,OUTER);
  2639.     else 
  2640.         @<Handle a comment@>@;
  2641. }
  2642.  
  2643. @ Deal with a comment inside C~text.
  2644. @<Handle a comment@>=
  2645. {
  2646. int bal; // Brace level in comment.
  2647.  
  2648. bal = copy_comment(1); next_control = @'|';
  2649.  
  2650. doing_cdir = NO;
  2651.  
  2652. while (bal>0)
  2653.     { /* Inside comment. */
  2654.     in_comment = YES;
  2655.     C_xref(part0,INNER);
  2656.  
  2657.     if (next_control==@'|') 
  2658.         bal = copy_comment(bal);
  2659.     else 
  2660.         bal = 0; // An error message will occur in phase 2.
  2661.     }
  2662. }
  2663.  
  2664. @ In the \TeX\ part of a module, cross-reference entries are made only for
  2665. the identifiers in \cee\ texts enclosed in~\Cb, or for control texts
  2666. enclosed in \.{@@\^}$\,\ldots\,$\.{@@>} or \.{@@.}$\,\ldots\,$\.{@@>} or
  2667. \.{@@9}$\,\ldots\,$\.{@@>}.
  2668.  
  2669. @<Store cross-references in the \T...@>=
  2670. {
  2671. the_part = TEX_;
  2672.  
  2673. WHILE() 
  2674.     {
  2675.     switch (next_control=skip_TeX()) 
  2676.         {
  2677.        @<Specific language cases@>:
  2678.         loc--; // Falls through to general case below.
  2679.  
  2680.        case L_switch:
  2681.         {
  2682.         @<Set the |language|...@>;
  2683.         continue;
  2684.         }
  2685.  
  2686.        case begin_nuweb:
  2687.         nuweb_mode = !NUWEB_MODE;
  2688.         continue;
  2689.  
  2690.        case toggle_output: 
  2691. @%        @<Toggle output@>@; 
  2692.         continue;
  2693.  
  2694.        case underline: 
  2695.         xref_switch = def_flag; 
  2696.         continue;
  2697.  
  2698. #ifdef DEBUG
  2699.        case trace: tracing=next_control-@'0'; continue;
  2700. #endif /* |DEBUG| */
  2701.  
  2702.        case @'|': 
  2703.         while(next_control <= module_name)
  2704.             {
  2705.             C_xref(TEX_,INNER); 
  2706.             if(next_control == @'|' || next_control == new_module) 
  2707.                 break;
  2708.             next_control = get_next();
  2709.             if(next_control == @'|') break;
  2710.             }
  2711.  
  2712.         break;
  2713.  
  2714.        case xref_roman: case xref_wildcard: case xref_typewriter: 
  2715.        case macro_module_name: case module_name: 
  2716.         loc-=2; next_control=get_next(); // Scan to \.{@@>}.
  2717.  
  2718.         if( !(next_control==module_name || 
  2719.             next_control==macro_module_name) )
  2720.                   new_xref(TEX_,id_lookup(id_first,id_loc,
  2721.                 (eight_bits)(next_control-identifier)));  
  2722.         break;
  2723.  
  2724.         case invisible_cmnt:
  2725.         loc = limit + 1;
  2726.         break;
  2727.         }
  2728.  
  2729.     if (next_control>=formatt) 
  2730.         break;
  2731.     }
  2732. }
  2733.  
  2734. @ During the definition and \cee\ parts of a module, cross-references are
  2735. made for all identifiers except reserved words; however, the identifiers in
  2736. a format definition are referenced even if they are reserved. The \TeX\
  2737. code in comments is, of course, ignored, except for \cee\ portions enclosed
  2738. in~\Cb; the text of a module name is skipped entirely, even if it contains
  2739. \Cb~constructions.
  2740.  
  2741. The variables |lhs| and |rhs| point to the respective identifiers involved
  2742. in a format definition.
  2743.  
  2744. @<Global...@>=
  2745.  
  2746. EXTERN name_pointer lhs, rhs; /* pointers to |byte_start| for format
  2747.                 identifiers */ 
  2748.  
  2749. @ When we get to the following code we have |next_control>=formatt|.
  2750.  
  2751. @d KILL_XREFS(name) no_xref |= !defn_mask.name
  2752. @d INDEX_SHORT index_short = index_flag = YES // Implicit \.{@@+}.
  2753.  
  2754. @<Store cross-references in the d...@>=
  2755. {
  2756. boolean no_xref0 = no_xref;
  2757.  
  2758. the_part = DEFINITION;
  2759.  
  2760. while (next_control<begin_code) 
  2761.     { /* |formatt| or |definition| or |WEB_definition| or \.{@@\#...}
  2762. command. */ 
  2763.     switch(next_control)
  2764.         {
  2765.          case WEB_definition:
  2766.         if(mark_defined.WEB_macro && lower_case_code)
  2767.             {
  2768.             defd_switch = YES;
  2769.             defd_type = M_MACRO;
  2770.             }
  2771.             
  2772.         KILL_XREFS(macros);
  2773.         INDEX_SHORT;
  2774.         break;
  2775.  
  2776.        case m_undef:
  2777.         KILL_XREFS(macros);
  2778.         INDEX_SHORT;
  2779.         break;
  2780.  
  2781.         case definition: 
  2782.         if(mark_defined.outer_macro && lower_case_code) 
  2783.             {
  2784.             defd_switch = YES; // Implied \.{@@[}.
  2785.             defd_type = D_MACRO;
  2786.             }
  2787.  
  2788.         KILL_XREFS(outer_macros);
  2789.         INDEX_SHORT;
  2790.         break;
  2791.  
  2792.        case undefinition:
  2793.         KILL_XREFS(outer_macros);
  2794.         INDEX_SHORT;
  2795.         break;
  2796.  
  2797.        case m_ifdef:
  2798.        case m_ifndef:
  2799.         xref_switch = def_flag; /* implied \.{@@\_} */
  2800.         INDEX_SHORT;
  2801.         break;
  2802.         }
  2803.  
  2804.     switch(next_control)
  2805.         {
  2806.        case formatt:
  2807.         @<Process a format definition@>@;
  2808.         break;
  2809.  
  2810.        case limbo_text:
  2811.         @<Absorb limbo text@>@;
  2812.         break;
  2813.  
  2814.        case op_def:
  2815.         @<Overload an operator@>@;
  2816.         break;
  2817.  
  2818.        case macro_def:
  2819.         @<Overload an identifier@>@;
  2820.         break;
  2821.  
  2822.        case invisible_cmnt:
  2823.         loc = limit + 1; // Skip the line.
  2824.  
  2825.        default:
  2826.         next_control=get_next();
  2827.         break;
  2828.         }
  2829.  
  2830.     outr_xref(DEFINITION);
  2831.     no_xref = no_xref0;
  2832.     }
  2833. }
  2834.  
  2835. @ The syntax of a format definition is ``\.{@@f\ new\_name\ old\_name}'' or
  2836. ``\.{@@f\ `\{\ 10}''.  Error messages for improper format definitions of
  2837. the first kind will be issued in phase two; for the second kind, in phase
  2838. one. For the first kind, our job in phase one is to define the |ilk| of a
  2839. properly formatted identifier, and to fool the |new_xref| routine into
  2840. thinking that the identifier on the right-hand side of the format
  2841. definition is not a reserved word.  For the second kind, we must actually
  2842. change the category code of a \TeX\ character, and that must be done in
  2843. phase one so future identifiers can be resolved properly.
  2844.  
  2845. @<Process a form...@>= 
  2846. {
  2847. eight_bits last_control,rhs_ilk;
  2848. LANGUAGE saved_language = language;
  2849.  
  2850. KILL_XREFS(formats);
  2851. INDEX_SHORT;
  2852.  
  2853. if(language==TEX) 
  2854.     language = C;
  2855.  
  2856. last_control = next_control = get_next(); /* Identifier or module name to be
  2857.                 formatted, or |ASCII| character. */
  2858.  
  2859. if (next_control==identifier || next_control==module_name) 
  2860.     @<Process an identifier or module name@>@;
  2861. else if(next_control==@'`')
  2862.     @<Change a category code@>@;
  2863.  
  2864. if(saved_language==TEX)
  2865.     language = saved_language;
  2866. }
  2867.  
  2868. @ Here we deal with format commands of the form ``\.{@@f\ new\_name\
  2869. old\_name}''.
  2870.  
  2871. @<Process an identifier...@>=
  2872. {
  2873. if(next_control==identifier)
  2874.     {
  2875.     lhs=id_lookup(id_first, id_loc, normal); 
  2876.     lhs->ilk=normal; 
  2877.  
  2878.     new_xref(DEFINITION,lhs);
  2879.     }
  2880. else 
  2881.     lhs = cur_module;
  2882.  
  2883. next_control=get_next();
  2884.  
  2885. if (next_control==identifier)  /* Format the lhs like this one. */
  2886.     {
  2887.      rhs=id_lookup(id_first, id_loc,normal);
  2888.  
  2889.     if(lhs != NULL)
  2890.         {
  2891.          if(last_control==identifier) 
  2892.             @<Format the left-hand side@>@;
  2893.         else 
  2894.             lhs->mod_ilk = rhs->ilk; 
  2895.                 // We're formatting a module name.
  2896.         }
  2897.  
  2898. /* Take care of the possibility that the rhs may not yet have been
  2899. encountered. */
  2900.     rhs_ilk = rhs->ilk;
  2901.     rhs->ilk=normal; 
  2902.  
  2903.     new_xref(DEFINITION,rhs);
  2904.  
  2905.     rhs->ilk=rhs_ilk;
  2906.  
  2907.     next_control=get_next();
  2908.     }
  2909. }
  2910.  
  2911. @ Set the appropriate format bit.
  2912. @<Format the left-hand side@>=
  2913. {
  2914. lhs->ilk = rhs->ilk; 
  2915.  
  2916. /* First turn off the old lhs bit (retaining all others), then add in the
  2917. new bit for the current language. */
  2918. #define RST_BIT(field) lhs->field = BOOLEAN(lhs->field & ~(boolean)language)\
  2919.      | (rhs->field & (boolean)language)
  2920.  
  2921. RST_BIT(reserved_word);
  2922. RST_BIT(Language);
  2923. RST_BIT(intrinsic_word);
  2924. RST_BIT(keyword);
  2925.  
  2926. #undef RST_BIT
  2927. }
  2928.  
  2929. @ Here we consider format commands of the form ``\.{@@f\ `\{\ 10}''.
  2930. |get_TeX|~leaves the (|outer_char|) constant string between
  2931. [|id_first|,|id_loc|). 
  2932. @<Change a category code@>=
  2933. {
  2934. if((next_control = get_TeX()) != constant)
  2935.   ERR_PRINT(W,"Invalid @@f command:  \
  2936. One of the representations `a, `\\a, or `^^M is required");
  2937. else
  2938.     {
  2939.     int c = TeX_char(); // Convert the |ASCII| code in |id_first|.
  2940.  
  2941.     next_control = get_next(); // Now expecting integer category code.
  2942.  
  2943.     if(next_control != constant) ERR_PRINT(W,"Invalid category code");
  2944.     else
  2945.         {
  2946.         TeX_CATEGORY cat;
  2947.  
  2948.         TERMINATE(id_loc,0);
  2949.         cat = (TeX_CATEGORY)ATOI(id_first); 
  2950.             // Numerical value of new cat code.
  2951.  
  2952.         if((int)cat < 0 || (int)cat > 15) 
  2953.             ERR_PRINT(W,"Category code must be between 0 and 15");
  2954.         else TeX[c] = cat; // Change the category code.
  2955.  
  2956.         next_control = get_next();
  2957.         }
  2958.     }
  2959. }
  2960.  
  2961. @ We require a special routine to obtain an |ASCII| character in \TeX's
  2962. representation after a~'\.`'.  On entry, |loc|~is positioned after
  2963. the~'\.`'.  The possible representations are~`\.{a}', `\.{\\a}',
  2964. or~`\.{\^\^M}'.
  2965.  
  2966. @<Part 2@>=@[
  2967.  
  2968. eight_bits get_TeX(VOID)
  2969. {
  2970. if(loc >= limit)
  2971.     {
  2972.     ERR_PRINT(W,"@@f line ends prematurely");
  2973.     return ignore;
  2974.     }
  2975.  
  2976. id_first = id_loc = mod_text + 1;
  2977.  
  2978. if(*loc == @'\\') *id_loc++ = *loc++;
  2979. else if(*loc == @'^' && *(loc+1) == @'^')
  2980.     { // \TeX's way of representing control characters.
  2981.     *id_loc++ = *loc++; @+ *id_loc++ = *loc++;
  2982.     }
  2983.  
  2984. if(*loc == @'@@')
  2985.     if(*(loc+1) == @'@@') loc++;
  2986.     else ERR_PRINT(W,"You should say `@@@@");
  2987.  
  2988. *id_loc++ = *loc++; // Position to next non-processed character.
  2989. *id_loc = '\0';
  2990.  
  2991. id_first = esc_buf(id_loc+1,mod_end,id_first,YES);
  2992. to_outer(id_first);
  2993.  
  2994. return constant;
  2995. }
  2996.  
  2997. @ Here we convert the constant obtained in the previous routine into an
  2998. |ASCII| character.
  2999. @<Part 2@>=@[
  3000.  
  3001. int TeX_char(VOID)
  3002. {
  3003. int c;
  3004.  
  3005. while(*id_first == @'\\') id_first++;
  3006.  
  3007. if(*id_first == @'^' && *(id_first+1) == @'^') 
  3008.     {
  3009.     c = *(id_first+2);
  3010.     if(c >= 64) c -= 64;
  3011.     else c += 64;
  3012.     }
  3013. else c = *id_first;
  3014.  
  3015. return c;
  3016. }
  3017.  
  3018. @ Limbo text commands have the form ``\.{@@l\ "abc\\ndef"}'', and must be
  3019. absorbed during phase one so they can be dumped out at the beginning of
  3020. phase two.
  3021.  
  3022. @<Absorb limbo text@>=
  3023. {
  3024. LANGUAGE language0 = language;
  3025.  
  3026. KILL_XREFS(limbo);
  3027.  
  3028. if(language==TEX)
  3029.     language = C; // In order to absorb strings properly.
  3030.  
  3031. insert_breaks = NO; // We want the string to be absorbed completely literally.
  3032.  
  3033. if((next_control = get_next()) != stringg)
  3034.     ERR_PRINT(W,"String must follow @@l");
  3035. else
  3036.     { // Begin by stripping off delimiting quotes.
  3037.     for(id_first++,id_loc--; id_first<id_loc; )
  3038.         {
  3039.         if(*id_first==@'@@')
  3040.             {
  3041.             if(*(id_first+1)==@'@@') 
  3042.                 id_first++;
  3043.             else 
  3044.               ERR_PRINT(W,"Double @@ should be used in strings");
  3045.             }
  3046.  
  3047. /* Deal with escape sequences. */
  3048.         if(*id_first == @'\\') 
  3049.             {
  3050.             id_first++; 
  3051. /* Splitting the following line before |HUGE| led to compiler problem with
  3052. VAX/VMS. */
  3053.             app_tok(esc_achar(
  3054. (CONST ASCII HUGE*HUGE*)&id_first))@;
  3055.             } 
  3056.         else 
  3057.             app_tok(*id_first++);
  3058.         }
  3059.  
  3060.     freeze_text; /* We'll know we've collected stuff because |text_ptr|
  3061. will be advanced. */
  3062.     }
  3063.  
  3064. insert_breaks = YES;
  3065.  
  3066. language = language0;
  3067. }
  3068.  
  3069. @ The syntax of an operator-overloading command is 
  3070. ``\.{@@v\ .IN.\ "\\in"\ +}''.
  3071.  
  3072. @<Overload an op...@>=
  3073. {
  3074. OPERATOR HUGE *p,HUGE *p1;
  3075.  
  3076. KILL_XREFS(v);
  3077.  
  3078. /* Look at the first field, which should be an operator or a dot-op. */
  3079. next_control = get_next();
  3080.  
  3081. if(next_control == identifier)
  3082.     ERR_PRINT(W,"For future compatibility, please use syntax `.NAME.' for \
  3083. overloading dot operators");
  3084.  
  3085. if(!(p=valid_op(next_control)))
  3086.     ERR_PRINT(W,"Operator after @@v is invalid");
  3087. else
  3088.     {
  3089.     if(get_next() != stringg)
  3090.         ERR_PRINT(W,"Second argument (replacement text) \
  3091. of @@v must be a quoted string");
  3092.     else
  3093.         {
  3094.         int k = language_num;
  3095.         OP_INFO HUGE *q = p->info + k;
  3096.         int n = id_loc - id_first - 2; /* Don't count the
  3097. string delimiters. */
  3098.         outer_char HUGE *s;
  3099.  
  3100.         if(q->defn) FREE_MEM(q->defn,"q->defn",STRLEN(q->defn)+1,
  3101.             outer_char);
  3102.         q->defn = GET_MEM("q->defn",n+1,outer_char);
  3103.  
  3104.         *(id_loc-1) = '\0'; // Kill off terminating quote.
  3105.  
  3106.         for(s=q->defn,id_first++; *id_first; s++)
  3107.             if(*id_first == @'\\')
  3108.                 {
  3109.                 id_first++; 
  3110.                 *s = XCHR(esc_achar((CONST ASCII HUGE
  3111. *HUGE*)&id_first));
  3112.                 } 
  3113.             else *s = XCHR(*id_first++);
  3114.  
  3115.         overloaded[k] = q->overloaded = YES;
  3116.  
  3117. /* There may be several representations with the same name. */
  3118.         for(p1=op; p1<op_ptr; p1++)
  3119.             {
  3120.             if(p1==p || !p1->op_name) continue;
  3121.  
  3122.             if(STRCMP(p1->op_name,p->op_name) == 0)
  3123.                 {
  3124.                 OP_INFO HUGE *q1 = p1->info + k;
  3125.  
  3126.                 if(q1->defn) FREE_MEM(q1->defn,"q1->defn",
  3127.                     STRLEN(q1->defn)+1,outer_char);
  3128.                 q1->defn = GET_MEM("q1->defn",n+1,outer_char);
  3129.                 STRCPY(q1->defn,q->defn);
  3130.                 q1->overloaded = YES;
  3131.                 }
  3132.             }
  3133.  
  3134. /* Get the new category and set it.  If the last construction isn't
  3135. recognized as a valid operator, the category is set to |expr|. */
  3136.         p = valid_op(next_control=get_next());
  3137.  
  3138.         q->cat = (p ? p->info[k].cat : expr);
  3139.         }
  3140.     }
  3141. }
  3142.  
  3143. @ The syntax for overloading an identifier is ``\.{@@w\ \It{id}\
  3144. "\dots"}'', or the string replacement text can be replaced by~'\..', which
  3145. means just prepend a backslash to make it into a macro name.
  3146.  
  3147. @d QUICK_FORMAT @'.' // The shorthand for overloading like itself.
  3148.  
  3149. @<Overload an id...@>=
  3150. {
  3151. if((next_control=get_next()) != identifier)
  3152.     ERR_PRINT(W,"Identifier must follow @@w");
  3153. else
  3154.     {
  3155.     name_pointer p = id_lookup(id_first,id_loc,normal);
  3156.     int n,offset;
  3157.     WV_MACRO HUGE *w;
  3158.     ASCII HUGE *s;
  3159.     ASCII HUGE *id_first0, HUGE *id_loc0;
  3160.  
  3161. /* Index the identifier (but not defined).  Force short identifiers to be
  3162. indexed. */
  3163.     KILL_XREFS(w);
  3164.     INDEX_SHORT;
  3165.     new_xref(DEFINITION, p);
  3166.  
  3167. /* Remember the first identifier. */
  3168.     id_first0 = id_first;
  3169.     id_loc0 = id_loc;
  3170.  
  3171.     switch(next_control=get_next())
  3172.         {
  3173.        case @'\\':
  3174.         if((next_control = get_next()) != identifier)
  3175.             {
  3176.             ERR_PRINT(W,"Identifier must follow '\\'");
  3177.             break;
  3178.             }
  3179.  
  3180.         next_control = ignore; /* We don't want to put the
  3181. identifier into the index. */
  3182.         goto quick_code;
  3183.  
  3184.  
  3185.        case QUICK_FORMAT:
  3186.         id_first = id_first0;
  3187.         id_loc = id_loc0;
  3188.  
  3189.     quick_code:
  3190.         offset = 1;
  3191.         n = id_loc - id_first + 1;
  3192.         *id_loc = '\0';
  3193.         goto fmt_like_string;    
  3194.     
  3195.        case stringg:
  3196.         {
  3197.         offset = 0;
  3198.         n = id_loc - id_first - 2; // Don't count quotes.
  3199.         *(id_loc-1) = '\0';
  3200.         id_first++; // Skip over opening quote.
  3201.  
  3202.          fmt_like_string:
  3203.         p->wv_macro = w = GET_MEM("wv_macro",1,WV_MACRO);
  3204.         w->text = GET_MEM("w->text",n+1,outer_char);
  3205.         
  3206.         if(offset) *w->text = @'\\';
  3207.  
  3208.         for(s=w->text + offset; *id_first; s++)
  3209.             if(*id_first == @'\\')
  3210.                 {
  3211.                 id_first++;
  3212.                 *s = esc_achar((CONST ASCII HUGE
  3213. *HUGE*)&id_first);  
  3214.                 }
  3215.             else *s = *id_first++;
  3216.  
  3217.         w->len = s - w->text;
  3218.  
  3219.         w->cat = (eight_bits)(upper_case_code ? 0 : expr); // Temporary
  3220.         }
  3221.         break;
  3222.  
  3223.        default:
  3224.         ERR_PRINT(W,"Second argument (replacement text) \
  3225. of @@w must be either a quoted string or '.' or have the form \\name");
  3226.         break;    
  3227.         }
  3228.     }
  3229. }
  3230.  
  3231. @ Finally, when the \TeX\ and definition parts have been treated, we have
  3232. |next_control>=begin_code|.
  3233.  
  3234. @<Store cross-references in the \cee...@>=
  3235. {
  3236. the_part = CODE;
  3237.  
  3238. if (next_control<=module_name) 
  3239. {  /* |begin_code| or |module_name| */
  3240. boolean beginning_module = YES;
  3241.  
  3242. if(next_control==begin_code)
  3243.     {
  3244.     params = global_params;
  3245.     frz_params();
  3246.     mod_xref_switch = NO;
  3247.     if(mark_defined.fcn_name && lower_case_code) 
  3248.         {
  3249.         defd_switch = YES; // Implicit \.{@@[}.
  3250.         defd_type = FUNCTION_NAME;
  3251.         }
  3252.     }
  3253. else 
  3254.     mod_xref_switch = def_flag;
  3255.  
  3256.   do 
  3257.     {
  3258.     if (next_control==module_name && cur_module) 
  3259.         new_mod_xref(cur_module);
  3260.  
  3261.     if(beginning_module)
  3262.     {
  3263.     if(mod_xref_switch) 
  3264.         next_control = get_next();
  3265.     else 
  3266.         next_control = @'='; // For |begin_code|.
  3267.  
  3268.     if(next_control==@'=')
  3269.          if( !nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input)
  3270.             || (language==TEX)) ) 
  3271.         @<Set up column mode@>@; 
  3272.  
  3273.     beginning_module = NO;
  3274.     }
  3275.    else next_control = get_next();
  3276.  
  3277.     outr_xref(CODE);
  3278.     } 
  3279. while ( next_control<=module_name); /* Hunt for new module. */
  3280.  
  3281. column_mode = NO;    /* Turn off the FORTRAN verbatim input mode. */
  3282. }
  3283. }
  3284.  
  3285. @ After phase one has looked at everything, we want to check that each
  3286. module name was both defined and used.  The variable |cur_xref| will point
  3287. to cross-references for the current module name of interest.
  3288.  
  3289. @<Global...@>=
  3290.  
  3291. EXTERN xref_pointer cur_xref; /* temporary cross-reference pointer */
  3292.  
  3293. @ The following recursive procedure
  3294. walks through the tree of module names and prints out anomalies.
  3295. @^recursion@>
  3296.  
  3297. @<Part 2@>=@[
  3298.  
  3299. SRTN mod_check FCN((p))
  3300.     name_pointer p C1("Print anomalies in subtree |p|.")@;
  3301. {
  3302.   if (p) 
  3303.     {
  3304.     mod_check(p->llink);
  3305.     cur_xref = (xref_pointer)p->xref;
  3306.  
  3307.     if (cur_xref->num <def_flag) 
  3308.         {
  3309.         SET_COLOR(warning);
  3310.             printf("\n! Never defined: <"); prn_id(p); putchar('>');
  3311.         mark_harmless; 
  3312. @.Never defined: <section name>@>
  3313.           }
  3314.  
  3315.     while (cur_xref->num >= def_flag) cur_xref = cur_xref->xlink;
  3316.  
  3317.     if (cur_xref==xmem) 
  3318.         {
  3319.         SET_COLOR(warning);
  3320.             printf("\n! Never used: <"); prn_id(p); putchar('>');
  3321.         mark_harmless; 
  3322. @.Never used: <section name>@>
  3323.           }
  3324.  
  3325.         mod_check(p->rlink);
  3326.     }
  3327. }
  3328.  
  3329. @ Start off at the top of the tree.
  3330. @<Print error messages about un...@>=
  3331.  
  3332. mod_check(root)
  3333.  
  3334. @* LOW-LEVEL OUTPUT ROUTINES.
  3335. The \TeX\ output is supposed to appear in lines at most |line_length|
  3336. characters long, so we place it into an output buffer. During the output
  3337. process, |out_line| will hold the current line number of the line about to
  3338. be output.
  3339.  
  3340. @d CHECK_OPEN // This is defined differently in \FTANGLE.
  3341.  
  3342. @<Global...@>=
  3343.  
  3344. EXTERN BUF_SIZE line_length;
  3345. EXTERN ASCII HUGE *out_buf; // Assembled characters.
  3346. EXTERN ASCII HUGE *out_end; // End of |out_buf|.
  3347.  
  3348. EXTERN ASCII HUGE *out_ptr; // Points to last character in |out_buf|.
  3349. EXTERN LINE_NUMBER out_line; // number of next line to be output.
  3350.  
  3351. @
  3352. @<Alloc...@>=
  3353.  
  3354. ALLOC(ASCII,out_buf,ABBREV(line_length),line_length,1); /* assembled
  3355.                             characters */ 
  3356. out_end = out_buf+line_length; /* end of |out_buf| */
  3357.  
  3358. @ The |flush_buffer| routine empties the buffer up to a given breakpoint,
  3359. and moves any remaining characters to the beginning of the next line.  If
  3360. the |per_cent| parameter is |YES|, a |'%'|~is appended to the line that is
  3361. being output; in this case the breakpoint~|b| should be strictly less than
  3362. |out_end|. If the |per_cent| parameter is |NO|, trailing blanks are
  3363. suppressed.  The characters emptied from the buffer form a new line of
  3364. output.
  3365.  
  3366. The same caveat that applies to |ASCII_write| applies to |c_line_write|. (??)
  3367.  
  3368. @d OUT_FILE tex_file
  3369. @d C_LINE_WRITE(n) 
  3370.     fflush(tex_file),FWRITE(out_buf+1,n,tex_file)
  3371. @d ASCII_LINE_WRITE(n) 
  3372.     fflush(tex_file),ASCII_file_write(tex_file,out_buf+1,(size_t)(n))@;
  3373. @d TEX_PUTXCHAR(c) PUTC(c) // Send an |outer_char| to the \.{TEX} file.
  3374. @d TEX_NEW_LINE PUTC('\n') // A newline to the \.{TEX} file.
  3375. @d TEX_PRINTF(s) fprintf(tex_file,s) // A string to the \.{TEX} file.
  3376.  
  3377. @<Part 2@>=@[
  3378.  
  3379. SRTN flush_buffer FCN((b,per_cent))
  3380.     ASCII HUGE *b C0("")@;
  3381.     boolean per_cent C1("Outputs from |out_buf+1| to |b|, \
  3382. where |b<=out_ptr|.")@;
  3383. {
  3384. ASCII HUGE *j; 
  3385. ASCII HUGE *out_start;
  3386.  
  3387. if(output_on)
  3388.     {
  3389.     out_start = out_buf + 1;
  3390.     j = b; // Pointer into |out_buffer|.
  3391.  
  3392. /* Remove trailing blanks. */
  3393.     if(!per_cent) 
  3394.         while (j>out_buf && *j==@' ') 
  3395.             j--;
  3396.  
  3397.     ASCII_LINE_WRITE(j-out_buf);
  3398.  
  3399.     if (per_cent) 
  3400.         TEX_PUTXCHAR('%');
  3401.  
  3402.     TEX_NEW_LINE; 
  3403.     out_line++;
  3404.  
  3405.     if (b<out_ptr) 
  3406.         {
  3407.         if(*out_start == @'%') 
  3408.             out_start++;
  3409.  
  3410.         STRNCPY(out_start,b+1,PTR_DIFF(size_t,out_ptr,b));
  3411.         }
  3412.  
  3413.     out_ptr -= b - out_start + 1;
  3414.     }
  3415. else 
  3416.     out_ptr = out_buf;
  3417. }
  3418.  
  3419. @ When we are copying \TeX\ source material, we retain line breaks that
  3420. occur in the input, except that an empty line is not output when the \TeX\
  3421. source line was nonempty. For example, a line of the \TeX\ file that
  3422. contains only an index cross-reference entry will not be copied. The
  3423. |fin_line| routine is called just before |get_line| inputs a new line,
  3424. and just after a line break token has been emitted during the output of
  3425. translated \cee\ text.
  3426.  
  3427. @<Part 2@>=@[
  3428.  
  3429. SRTN fin_line(VOID) /* do this at the end of a line */
  3430. {
  3431. ASCII HUGE *k; /* pointer into |cur_buffer| */
  3432.  
  3433. if (out_ptr>out_buf) flush_buffer(out_ptr,NO); // Something nontrivial in line.
  3434. else 
  3435.     {
  3436. /* Don't output an empty line when \TeX\ source line is nonempty. */
  3437.     for (k=cur_buffer; k<=limit; k++)
  3438.           if (*k!=@' ' && *k!=tab_mark) return;
  3439.  
  3440.     flush_buffer(out_buf,NO); // Empty line.
  3441.     }
  3442. }
  3443.  
  3444. @ In particular, the |fin_line| procedure is called near the very
  3445. beginning of phase two. We initialize the output variables in a slightly
  3446. tricky way so that the first line of the output file will be `\.{\\input
  3447. fwebmac}'.  This is the default. However, occasionally, one may need to
  3448. load other macro packages before \.{fwebmac}. To prevent this first line to
  3449. be generated, use the command line option~``\.{-w}''.  To change the name
  3450. of the default, way ``\.{-wnew\_name}''---for example, ``\.{-wfmac.sty}''.
  3451.  
  3452. @<Set init...@>=
  3453. {
  3454. out_ptr = out_buf; out_line = 1; 
  3455.  
  3456. if(input_macros) 
  3457.     {
  3458.     TEX_PRINTF("\\input ");
  3459.     OUT_STR(*fwebmac ? fwebmac : w_style.misc.macros); /* The command
  3460. line overrides the style file. */
  3461.     }
  3462. }
  3463.  
  3464. @ When the `\.{@@I}'~command is used in conjunction with the command-line
  3465. option `\.{-i}', we process the incoming text, but don't write it out. We
  3466. need an output flag to tell us when output is allowed.
  3467.  
  3468. @<Glob...@>=
  3469.  
  3470. EXTERN boolean output_on SET(YES);
  3471.  
  3472. @ When we wish to append one character~|c| to the output buffer, we write
  3473. `|out(c)|'; this will cause the buffer to be emptied if it was already
  3474. full.  |c|~is assumed to be of type |ASCII|.  If we want to append more
  3475. than one character at once, we say |OUT_STR(s)|, where |s|~is a string
  3476. containing the characters, or |out_del_str(s,t)| (``output a delimited
  3477. string''), where~|s| and~|t| point to the same array of characters (stored
  3478. as 16-bit tokens); characters from~|s| to~|t-1|, inclusive, are output. The
  3479. |out_str| routine takes an |outer_char| string as an argument, since this
  3480. is typically used as a print statement from inside the code.
  3481.  
  3482. A line break will occur at a space or after a single-nonletter \TeX\
  3483. control sequence.
  3484.  
  3485. @d out(c) {if (out_ptr>=out_end) break_out(); 
  3486.         *(++out_ptr)=(ASCII)(c);}
  3487.  
  3488. @d OUT_STR(s) out_str(OC(s))
  3489.  
  3490. @<Part 2@>=@[
  3491.  
  3492. SRTN out_del_str FCN((s,t)) /* output |ASCII| characters from |s| to |t-1|.  */
  3493.     token_pointer s C0("")@;
  3494.     token_pointer t C1("")@;
  3495. {
  3496. if(!output_on) 
  3497.     return; // Skip output.
  3498.  
  3499. while (s<t) 
  3500.     out(*s++);
  3501. }
  3502.  
  3503. SRTN out_str FCN((s)) /* output characters from |s| to end of string */
  3504.     CONST outer_char HUGE *s C1("")@;
  3505. {
  3506. if(!output_on) 
  3507.     return; // Skip output.
  3508.  
  3509. while (*s) 
  3510.     out(XORD(*s++));
  3511. }
  3512.  
  3513. @ Here we write an |outer_char| file name. We have to watch out for special
  3514. characters. 
  3515. @<Part 2@>=@[
  3516.  
  3517. SRTN out_fname FCN((s))
  3518.     CONST outer_char HUGE *s C1("File name to be written.")@;
  3519. {
  3520. ASCII a;
  3521.  
  3522. while(*s)
  3523.     {
  3524.     a = XORD(*s++);
  3525.  
  3526.     switch(a)
  3527.         {
  3528.         @<Special string cases@>:
  3529.             out(@'\\');
  3530.             break;
  3531.         }
  3532.     out(a);
  3533.     }
  3534. }
  3535.  
  3536. @ The |break_out| routine is called just before the output buffer is about
  3537. to overflow. To make this routine a little faster, we initialize position~0
  3538. of the output buffer to~'\.\\'; this character isn't really output.
  3539.  
  3540. @<Set init...@>=
  3541.  
  3542. out_buf[0] = @'\\';
  3543.  
  3544. @ A long line is broken at a blank space or just before a backslash that
  3545. isn't preceded by another backslash. In the latter case, a~|'%'| is output
  3546. at the break.
  3547.  
  3548. @<Part 2@>=@[
  3549.  
  3550. SRTN break_out(VOID) /* finds a way to break the output line */
  3551. {
  3552. ASCII HUGE *k = out_ptr; /* pointer into |out_buf| */
  3553. boolean is_tex_comment = BOOLEAN(*(out_buf+1) == @'%');
  3554.  
  3555. WHILE()
  3556.     {
  3557.     if (k==out_buf) @<Print warning message, break the line,
  3558.                     |return|@>; 
  3559.  
  3560.     if (*k==@' ') 
  3561.         {
  3562.         flush_buffer(k,NO); break;
  3563.         }
  3564.  
  3565.     if (*(k--)==@'\\' && *k!=@'\\') 
  3566.         { /* we've decreased |k| */
  3567.         flush_buffer(k,YES); break;
  3568.         }
  3569.     }
  3570.  
  3571. if(is_tex_comment) *(++out_ptr) = @'%';
  3572. }
  3573.  
  3574. @ We get to this module only in unusual cases that the entire output line
  3575. consists of a string of backslashes followed by a string of nonblank
  3576. non-backslashes. In such cases it is almost always safe to break the line
  3577. by putting a~|'%'| just before the last character.
  3578.  
  3579. @<Print warning message...@>=
  3580. {
  3581. SET_COLOR(warning);
  3582.   printf("\n! Line had to be broken (output l. %lu):\n",out_line);
  3583. @.Line had to be broken@>
  3584.   ASCII_write(out_buf+1, out_ptr-out_buf-1);
  3585.   new_line; mark_harmless;
  3586.   flush_buffer(out_ptr-1,YES); return;
  3587. }
  3588.  
  3589. @ Here is a macro that outputs a module number in decimal notation.  The
  3590. number to be converted by |out_mod| is known to be less than |def_flag|, so
  3591. it cannot have more than five decimal digits.  If the module is changed, we
  3592. output~`\.{\\*}' just after the number.
  3593.  
  3594. @<Part 2@>=@[
  3595.  
  3596. SRTN out_mod FCN((n,encap))
  3597.     sixteen_bits n C0("Module number.")@;
  3598.     boolean encap C1("Encapsulate?")@;
  3599. {
  3600. char s[100];
  3601.  
  3602. if(encap)
  3603.     sprintf(s,"%s%s%u%s",
  3604.         w_style.indx.encap_prefix,w_style.indx.encap_infix
  3605.         ,n
  3606.         ,w_style.indx.encap_suffix); 
  3607. else
  3608.     sprintf(s,"%u",n);
  3609.  
  3610. OUT_STR(s);
  3611.  
  3612. if(chngd_module[n]) OUT_STR("\\*");
  3613. }
  3614.  
  3615. @ The |out_name| procedure is used to output an identifier or index entry,
  3616. enclosing it in braces. When we're outputting an identifier, we must escape
  3617. the various special characters that may sneak in. Index entries are treated
  3618. literally.
  3619.  
  3620. @d IDENTIFIER YES
  3621. @d INDEX_ENTRY NO
  3622.  
  3623. @<Part 2@>=@[
  3624.  
  3625. SRTN out_name FCN((is_id,p))
  3626.     boolean is_id C0("Flag to distinguish identifier/index entry.")@;
  3627.     name_pointer p C1("The name to be output.")@;
  3628. {
  3629. ASCII HUGE *k,  HUGE *k_end=(p+1)->byte_start; // Pointers into |byte_mem|.
  3630. boolean multi_char,non_TeX_macro;
  3631. sixteen_bits mod_defined;
  3632.  
  3633. if(!output_on) 
  3634.     return; // Skip output.
  3635.  
  3636. multi_char = BOOLEAN(k_end - p->byte_start > 1);
  3637.  
  3638. if(multi_char) 
  3639.     out(@'{');// Multiple-letter identifiers are enclosed in braces.
  3640.  
  3641. non_TeX_macro = BOOLEAN(*p->byte_start == @'\\' && language != TEX);
  3642.  
  3643. if(non_TeX_macro) 
  3644.     out(@'$'); // \Cpp\ macros must be in math mode.
  3645.  
  3646. for (k=p->byte_start; k<k_end; k++) 
  3647.     {
  3648.     if(is_id)
  3649.         switch(*k)
  3650.             { /* Escape the special characters in identifiers. */
  3651.            case @'\\':
  3652.            case @'{': case @'}': 
  3653. /* A non-\TeX\ identifier can result from the translation of an operator
  3654. name in \Cpp.  For that, we shouldn't escape the opening backslash.  We
  3655. also assume that any braces following that macro should be interpreted
  3656. literally. */
  3657.             if(non_TeX_macro) 
  3658.                 break; 
  3659.  
  3660.            @<Other string cases@>:
  3661.             out(@'\\');
  3662.             }
  3663.  
  3664.     out(*k);
  3665.     }
  3666.  
  3667. if(non_TeX_macro) 
  3668.     out(@'$');
  3669. if(multi_char) 
  3670.     out(@'}');
  3671.  
  3672. if(p->wv_macro)
  3673.     @<Output the overloaded translation@>@;
  3674.  
  3675. /* Should do all languages here. (Sorted!). */
  3676. if(subscript_fcns && (mod_defined = p->defined_in(language)))
  3677.     {
  3678.     char temp[100];
  3679.  
  3680.     sprintf(temp,"\\WIN%d{%d}",DEFINED_TYPE(p),
  3681.         mod_defined==module_count ? 0 : mod_defined);
  3682.     OUT_STR(temp);
  3683.     }
  3684. }
  3685.  
  3686. @
  3687. @<Output the overlo...@>=
  3688. {
  3689. WV_MACRO HUGE *w = p->wv_macro;
  3690. ASCII HUGE *s = w->text;
  3691.  
  3692. OUT_STR("\\WTeX{");
  3693.  
  3694. while(*s)
  3695.     out(*s++);
  3696.  
  3697. out(@'}');
  3698. }
  3699.  
  3700. @ The following can occur in identifiers recognized by \FWEB.
  3701. @<Special identifier cases@>=
  3702.  
  3703. case @'_':
  3704. case @'$':
  3705. case @'%':
  3706. case @'#':
  3707. case @'\\':
  3708.     out(@'\\')@;
  3709.  
  3710. @* ROUTINES THAT COPY \TeX\ MATERIAL.  During phase two, we use the
  3711. subroutines |copy_limbo| and |copy_TeX| in place of the analogous
  3712. |skip_limbo| and |skip_TeX| that were used in phase one. The routine
  3713. |copy_comment| serves for both phases.
  3714.  
  3715. The |copy_limbo| routine, for example, begins by outputting two kinds of
  3716. \TeX\ code that it has constructed or collected.  First, it writes out
  3717. \TeX\ definitions for user-defined dot constants; second, it writes out any
  3718. limbo text that it collected during phase one.  Then it takes \TeX\
  3719. material that is not part of any module and transcribes it almost verbatim
  3720. to the output file.  No `\.{@@}'~signs should occur in such material except
  3721. in `\.{@@@@}'~pairs; such pairs are replaced by singletons.
  3722.  
  3723. @<Part 2@>=@[
  3724.  
  3725. SRTN copy_limbo(VOID)
  3726. {
  3727. ASCII c;
  3728.  
  3729. @<Output default definitions for user-defined dot constants@>@;
  3730. @<Output any limbo text definitions@>@;
  3731.  
  3732. OUT_STR("\n% --- Beginning of user's limbo section ---");
  3733. flush_buffer(out_ptr,NO);
  3734.  
  3735. WHILE()
  3736.     {
  3737.         if (loc>limit && (fin_line(), !get_line())) return;
  3738.  
  3739.         *(limit+1)=@'@@';
  3740.  
  3741.         while (*loc!=@'@@') out(*(loc++)); // Copy verbatim to output.
  3742.  
  3743.         if (loc++<=limit) 
  3744.         {
  3745.           c=*loc++;     // Character after `\.{@@}'.
  3746.  
  3747.           if (ccode[c]==new_module) break;
  3748.  
  3749.           if (c!=@'z' && c!=@'Z')
  3750.             switch(ccode[c])
  3751.                 {
  3752.                @<Cases to set |language| and |break|@>@:@;
  3753.  
  3754.             case toggle_output: 
  3755.                 out_skip();
  3756.                 break; 
  3757.  
  3758.             case invisible_cmnt:
  3759.                 loc = limit + 1; // Skip entire rest of line.
  3760.                 break;
  3761.  
  3762.             case @'@@':
  3763.                     out(@'@@'); // $\.{@@@@} \to \.{@@}$.
  3764.                 break;
  3765.  
  3766.             default:
  3767.                   ERR_PRINT(W,"Double @@ required\
  3768.  outside of sections"); 
  3769. @.Double \AT! required...@>
  3770.                  }
  3771.         }
  3772.     }
  3773. }
  3774.  
  3775. @ By the beginning of phase~2, we know about any user-defined operators in
  3776. \Fortran-90 via the \.{@@v}~command.  Here we output default (empty)
  3777. definitions of the associated 
  3778. macros.  The user can override these in his limbo section.
  3779.  
  3780. @<Output default def...@>=
  3781. {
  3782. int k;
  3783. OPERATOR *p;
  3784.  
  3785. /* An extra blank line after \.{\\input fwebmac.sty}. */
  3786. for(k=0; k<NUM_LANGUAGES; k++)
  3787.     if(overloaded[k])
  3788.         {
  3789.         flush_buffer(out_ptr,NO);
  3790.         break;
  3791.         }
  3792.  
  3793. for(k=0; k<NUM_LANGUAGES; k++)
  3794.     if(overloaded[k])
  3795.         {
  3796.         flush_buffer(out_ptr,NO);
  3797.  
  3798.            OUT_STR("% --- Overloaded operator definitions from @@v for '");
  3799.         OUT_STR(lang_codes[k]);
  3800.         OUT_STR("' ---");
  3801.         flush_buffer(out_ptr,NO);
  3802.  
  3803.         for(p=op; p<op_ptr; p++)
  3804.             {
  3805.             OP_INFO HUGE *q = p->info + k;
  3806.  
  3807.             if(q->overloaded)
  3808.                 @<Define to \TeX\ an overloaded operator@>@;
  3809.             }
  3810.  
  3811.         flush_buffer(out_ptr,NO);
  3812.         }
  3813. }
  3814.  
  3815. @ This fragment produces output of the form
  3816. ``\.{\\newbinop\{abc\}\{C\{def\}}''.  See \.{fwebmac.web} to learn how such
  3817. macros are defined.
  3818.  
  3819. @<Define to \TeX\ ...@>=
  3820. @{
  3821. #define TEMP_LEN 1000
  3822.  
  3823. outer_char temp[TEMP_LEN], outer_op_name[100];
  3824.  
  3825. OUT_STR("\\new");
  3826.  
  3827. switch(q->cat)
  3828.     {
  3829.     case unorbinop:
  3830.     case binop:
  3831.         OUT_STR("binop"); @+ break;
  3832.  
  3833.     case unop:
  3834.         OUT_STR("unop"); @+ break;
  3835.  
  3836.     default:
  3837.         OUT_STR("op"); @+ break;
  3838.     }
  3839.  
  3840. STRCPY(outer_op_name,p->op_name); @+ to_outer((ASCII *)outer_op_name);
  3841. SPRINTF(TEMP_LEN,temp,`"{%s}{%s}{%s} ",outer_op_name,lang_codes[k],q->defn`);
  3842. OUT_STR(temp);
  3843.  
  3844. #undef TEMP_LEN
  3845. }
  3846.  
  3847. @ Limbo text material is collected from all \.{@@l}~commands, then output
  3848. verbatim here, at the beginning of phase two.  We begin by writing out any
  3849. default material from the style file entry \.{limbo}.
  3850. @<Output any limbo text...@>=
  3851. {
  3852. text_pointer t = tok_start + 1;
  3853.  
  3854. /* Default material. */
  3855. if(*w_style.misc.limbo)
  3856.     {
  3857.     flush_buffer(out_ptr,NO);
  3858.     OUT_STR("% --- Limbo text from style file ---");
  3859.     flush_buffer(out_ptr,NO);
  3860.     OUT_STR(w_style.misc.limbo);
  3861.     flush_buffer(out_ptr,NO);
  3862.     }
  3863.  
  3864. /* If there were any \.{@@l}~commands, they were stored in phase~1; output
  3865. them now. */
  3866. if(text_ptr > t)
  3867.     {
  3868.     flush_buffer(out_ptr,NO);
  3869.     OUT_STR("% --- Limbo text from @@l ---"); // Header line.
  3870.     flush_buffer(out_ptr,NO);
  3871.     }
  3872.  
  3873. /* Actual text. */
  3874. for(; t<text_ptr; t++)
  3875.     {
  3876.     out_del_str(*t,*(t+1));
  3877.     flush_buffer(out_ptr,NO);
  3878.     }
  3879.  
  3880. @<Initialize |tok_ptr|...@>@;
  3881. }
  3882.  
  3883. @
  3884. @<Unused@>=
  3885.  
  3886. if(Fortran88)
  3887.     {
  3888.     DOTS *d;
  3889.  
  3890.     flush_buffer(out_ptr,NO);
  3891.  
  3892.     for(d=dots + PREDEFINED_DOTS; d->code; d++)
  3893.         if(d->code == dot_const) 
  3894.             fprintf(tex_file,"\\newdot{%s}{} ",d->symbol);
  3895.  
  3896.     if(d-dots > PREDEFINED_DOTS + 1) flush_buffer(out_ptr,NO);
  3897.     }
  3898.  
  3899. @ A fragment that toggles the output switch.  This is used in conjunction
  3900. with the \.{@@i}~command, which is translated into a |toggle_output|.
  3901.  
  3902. @<Glob...@>=
  3903.  
  3904. EXTERN boolean strt_off SET(NO), ending_off SET(NO);
  3905.  
  3906. @
  3907. @<Toggle output@>=
  3908. {
  3909. static int outer_include_depth;
  3910.  
  3911. if(output_on)
  3912.     {
  3913.     if(phase==2) 
  3914.         {
  3915.         flush_buffer(out_ptr,NO);
  3916.         }
  3917.     outer_include_depth = incl_depth;
  3918.     output_on = NO;
  3919.     }
  3920. else if(incl_depth <= outer_include_depth) 
  3921.     {
  3922.     output_on = YES;
  3923.     }
  3924. }
  3925.  
  3926. @ While appending code text, store the state of the output.
  3927. @
  3928. @<Store the output switch@>=
  3929. {
  3930. if(output_on) app(Turn_output_on);
  3931. else
  3932.     {    
  3933.     app(force); /* If we don't do this, output is turned off before the
  3934. contents of the last line are printed. */
  3935.     app(turn_output_off);
  3936.     }
  3937.  
  3938. app_scrap(ignore_scrap,no_math);
  3939. }
  3940.  
  3941. @ While appending code text, store the state of the output.
  3942. @
  3943. @<Store output switch and \.{\\Wskipped}@>=
  3944. {
  3945. if(output_on) app(Turn_output_on);
  3946. else
  3947.     {    
  3948.     app(force);
  3949.     app(Turn_output_off);
  3950.     }
  3951.  
  3952. app_scrap(ignore_scrap,no_math);
  3953. }
  3954.  
  3955. @ The |copy_TeX| routine processes the \TeX\ code at the beginning of a
  3956. module; for example, the words you are now reading were copied in this way.
  3957. It returns the next control code or~`\v' found in the input.  Lines that
  3958. consist of all spaces are made empty; spaces between the beginning of a
  3959. line and an \.{@@}~command are stripped away.  (Unlike the original design,
  3960. we leave tab marks in, since some users use those as active characters.)
  3961. This makes the test for empty lines in |fin_line| work.
  3962.  
  3963. @<Part 2@>=@[
  3964. eight_bits copy_TeX(VOID)
  3965. {
  3966. ASCII c; // Current character being copied.
  3967.  
  3968. WHILE()
  3969.     {
  3970.     if (loc>limit)
  3971.         {
  3972.         @<Delete run of spaces between beginning of line and
  3973. present position@>@;
  3974.         fin_line();
  3975.  
  3976.         if(!get_line()) 
  3977.             return new_module;
  3978.         }
  3979.  
  3980.     *(limit+1)=@'@@';
  3981.  
  3982. scan:
  3983.     while ((c=*(loc++))!=@'|' && c!=@'@@')
  3984.         {
  3985.         if(c==interior_semi) 
  3986.             c = @';';
  3987.          out(c); // Copy \TeX\ verbatim to output.
  3988.  
  3989. #if(0)
  3990.         if (out_ptr==out_buf+1 && (c==@' '
  3991.                  || c==tab_mark
  3992.             )) out_ptr--; 
  3993. #endif
  3994.         }
  3995.  
  3996.     if (c==@'|') 
  3997.         return @'|'; // Beginning of code mode.
  3998.  
  3999.     if (loc<=limit)
  4000.         { /* Found an \.{@@}. */
  4001.         eight_bits cc;
  4002.  
  4003.         if(*loc == @'@@')
  4004.             {
  4005.             out(@'@@');
  4006.             loc++;
  4007.             goto scan;
  4008.             }
  4009.  
  4010.         @<Delete run of spaces...@>@;
  4011.  
  4012.         SET_CASE(*loc);
  4013.  
  4014.         if( (cc = ccode[*(loc++)]) != big_line_break) 
  4015.             return cc;
  4016.  
  4017.         if(loc >= limit) 
  4018.             return cc;
  4019.  
  4020.         @<Process possible pre...@>; // An `\.{@@\#\dots}' command.
  4021.         return cc; // A |big_line_break| command.
  4022.         }
  4023.     }
  4024.  
  4025. DUMMY_RETURN(ignore);
  4026. }
  4027.  
  4028. @ If there are only spaces between the beginning of the output buffer and
  4029. the present position |out_ptr|, delete those spaces.
  4030. @<Delete run of spaces...@>=
  4031. {
  4032. ASCII HUGE *b;
  4033.  
  4034. for(b=out_buf+1; b<=out_ptr; b++)
  4035.     if(*b != @' ') 
  4036.         break;
  4037.  
  4038. if(b > out_ptr) 
  4039.     out_ptr = out_buf;
  4040. }
  4041.  
  4042. @ A flag lets us know when we're processing a comment.
  4043. @<Glob...@>=
  4044.  
  4045. EXTERN boolean in_comment;
  4046.  
  4047. @ The |copy_comment| function issues a warning if more braces are opened
  4048. than closed, and in the case of a more serious error it supplies enough
  4049. braces to keep \TeX\ from complaining about unbalanced braces. (Because of
  4050. a bug inherited from \CWEB, this doesn't work right if there is a
  4051. construction such as~`\.{\\\{}' in the comment.)  Instead of copying the
  4052. \TeX\ material into the output buffer, this function copies it into the
  4053. token memory.  The abbreviation |app_tok(t)| is used to append token~|t| to
  4054. the current token list, and it also makes sure that it is possible to
  4055. append at least one further token without overflow.
  4056.  
  4057. @d app_tok(c) {if (tok_ptr+2>tok_m_end)
  4058.             OVERFLW("tokens",ABBREV(max_toks_w)); 
  4059.         app(c);} 
  4060.  
  4061. @<Part 2@>=@[
  4062.  
  4063. int copy_comment FCN((bal)) /* copies \TeX\ code in comments */
  4064.     int bal C1("Brace balance.")@;
  4065. {
  4066. ASCII c; //* Current character being copied.
  4067. char terminator[2];
  4068. token_pointer tok_ptr0 = tok_ptr;
  4069.  
  4070. in_comment = YES;
  4071.  
  4072. terminator[0] = *limit; @+ terminator[1] = *(limit+1);
  4073.  
  4074. *limit = @' '; /* Space to implement continued line.  Short commands will
  4075.             be ended by this space. */
  4076.  
  4077. /* Especially when it comes to stars and asterisks, we need to know when
  4078. we're copying \TeX. Since this is actually going into token memory instead
  4079. of being transcribed directly to the output, we append the |copy_mode| flag
  4080. to help us know where we are. For this to work properly, one must return
  4081. only from the bottom of this function, because we append another
  4082. |copy_mode| at the bottom. */
  4083. if(phase == 2) 
  4084.     app_tok(copy_mode);
  4085.  
  4086. WHILE()
  4087.     {
  4088.     if(loc > limit) 
  4089.         @<Continue comment if necessary@>@;
  4090.  
  4091. // Get the next character.  Convert a run of tabs into one tab.
  4092.     if(language==TEX) 
  4093.         c = *loc++;
  4094.     else do 
  4095.         c = *(loc++);
  4096.     while(c == tab_mark);
  4097.  
  4098.         if (c==@'|') break; // Found beginning of code mode.
  4099.  
  4100.     if (c==@'*' && *loc==@'/' && long_comment) 
  4101.         {
  4102.         loc++; // Position after `\.{\starslash}'.
  4103.  
  4104.         @<Finish comment and |break|@>;
  4105.         }
  4106.  
  4107. /* It looks better in the \.{tex} file if tabs are replaced by spaces.
  4108. Presumably this won't harm anything else. */
  4109.         if (phase==2) 
  4110.         @<Append comment text@>@;
  4111.  
  4112.         @<Copy special things when |c=='@@', '\\', '{', '}'|@>; 
  4113.     }
  4114.  
  4115. if(phase == 2) 
  4116.     app_tok(copy_mode); // Negate the copying mode.
  4117.  
  4118. *limit = terminator[0]; @+ *(limit+1) = terminator[1];
  4119.  
  4120. if(!long_comment && *limit == @'@@' && loc > limit) 
  4121.     loc = limit;
  4122.  
  4123. in_comment = NO;
  4124. return bal;
  4125. }
  4126.  
  4127. @
  4128. @<Continue comment if nec...@>=
  4129. {
  4130. if(!(long_comment || language==TEX))
  4131.     { // End of short comment.
  4132.     if(auto_semi && *(tok_ptr-2) == @';' &&    *(tok_ptr-1) == @' ')
  4133.             tok_ptr -= 2;
  4134.  
  4135. /* Strip trailing spaces. */
  4136.     while(*(tok_ptr-1) == @' ') 
  4137.         tok_ptr--;
  4138.  
  4139. /* If the last space happened to be escaped, kill the escape. */
  4140.     if(*(tok_ptr-1) == @'\\' && *(tok_ptr-2) != @'\\') 
  4141.         tok_ptr--;
  4142.  
  4143. /* Kill the trailing end-of-comment. */
  4144.     if(*(tok_ptr-2)==@'*' && *(tok_ptr-1)==@'/') 
  4145.         tok_ptr -= 2;
  4146.  
  4147.     @<Finish comment and |break|@>@;
  4148.     }
  4149.  
  4150. if (!get_line())
  4151.     {
  4152.     if(language!=TEX)
  4153.        ERR_PRINT(W,"Input ended in mid-comment");
  4154. @.Input ended in mid-comment@>
  4155.         loc=cur_buffer+1; @<Clear |bal| and |break|@>;
  4156.     }
  4157.  
  4158. /* For \TeX, we concatenate adjacent lines that all begin with comment
  4159. characters. */
  4160. if(language==TEX)
  4161.     {
  4162.     if(loc==limit) @<Finish comment...@>@;
  4163.  
  4164.     for(;loc <= limit; loc++)
  4165.       if(*loc!=@' ' && *loc!=tab_mark) break;
  4166.  
  4167.     if(loc > limit) continue;
  4168.  
  4169.     if(TeX[*loc] == TeX_comment) loc++;
  4170.     else 
  4171.         { // Unskip the white space.
  4172.         loc = cur_buffer;
  4173.         @<Finish comment...@>@;
  4174.         }
  4175.     }                
  4176. }
  4177.  
  4178. @ During phase~2, we must actually append the text character by character.
  4179. That's essentially straightforward, but a few replacements are made.
  4180.  
  4181. @<Append comment text@>=
  4182. switch(c)
  4183.     {
  4184.    case tab_mark:
  4185.     if(language==TEX) 
  4186.         APP_STR("\\quad");
  4187.     else 
  4188.         app_tok(@' '); 
  4189.  
  4190.     break;
  4191.  
  4192.    case interior_semi:
  4193.     app_tok(@';'); 
  4194.     break;
  4195.  
  4196.    case @'%':
  4197.     if(language==TEX)
  4198.         app_tok(@'\\');
  4199.  
  4200.     app_tok(c);
  4201.     break;
  4202.  
  4203.    default:
  4204. /* Basically, we just append the present character here.  However, compiler
  4205. directives need to be escaped. */
  4206.     if(doing_cdir)
  4207.         switch(c)
  4208.             {
  4209.             @<Special string cases@>:
  4210.             app_tok(@'\\');
  4211.             }
  4212.  
  4213.     app_tok(c); 
  4214.     break;
  4215.     }
  4216.  
  4217. @ This fragment finishes off a comment, ensuring that braces are properly
  4218. balanced. 
  4219. @<Finish comment...@>=
  4220.  
  4221. if(bal==1) 
  4222.     {
  4223.     if (phase==2) 
  4224.         {
  4225.         if(language==TEX) @<Check for a null \TeX\ comment@>@;
  4226.         app_tok(@'}'); 
  4227.         }
  4228.     bal = 0;
  4229.     break;
  4230.     }
  4231. else 
  4232.     {
  4233.     ERR_PRINT(W,"Braces don't balance in comment");
  4234. @.Braces don't balance in comment@>
  4235.     @<Clear |bal| and |break|@>;
  4236.     }
  4237.  
  4238. @
  4239. @<Check for a null ...@>=
  4240. {
  4241. token_pointer t;
  4242.  
  4243. for(t=tok_ptr-1; t>tok_ptr0; t--)
  4244.     if(*t != @' ') break;
  4245.  
  4246. if(t == tok_ptr0 && *(t-4)==@'\\' && *(t-3)==@'W' && *(t-2)==@'C' &&
  4247.         *(t-1)==@'{')
  4248.     *(tok_ptr0-2) = @'x'; // Change \.{\\WC} to \.{\\Wx}.
  4249. }
  4250.  
  4251.  
  4252. @<Copy special things when |c=='@@'...@>=
  4253.  
  4254. if (c==@'@@') 
  4255.     {
  4256.       if (*(loc++)!=@'@@') 
  4257.         {
  4258.             ERR_PRINT(W,"Illegal use of @@ in comment");
  4259. @.Illegal use of \AT!...@>
  4260.             loc-=2; if (phase==2) tok_ptr--; @<Clear |bal|...@>;
  4261.           }
  4262.     }
  4263. else if (c==@'\\' && *loc!=@'@@' && phase==2) app_tok(*(loc++))@;
  4264. else if (c==@'{') bal++;
  4265. else if (c==@'}') bal--;
  4266.  
  4267. @ When the comment has terminated abruptly due to an error, we output
  4268. enough right braces to keep \TeX\ happy.
  4269.  
  4270. @<Clear |bal|...@>=
  4271.  
  4272. app_tok(@' '); /* this is done in case the previous character was~`\.\\' */
  4273.  
  4274. while (bal-- >0) app_tok(@'}');
  4275.  
  4276. bal = 0;
  4277. break;
  4278.  
  4279. @i scraps.hweb /* Declarations related to the scraps and productions. */
  4280.  
  4281. @
  4282. @<Alloc...@>=
  4283.  
  4284. ALLOC(scrap,scrp_info,ABBREV(max_scraps),max_scraps,0);
  4285. scrp_end=scrp_info+max_scraps -1; /* end of |scrp_info| */  
  4286.  
  4287. @<Set init...@>=
  4288.  
  4289. scrp_base=scrp_info+1;
  4290.  
  4291. mx_scr_ptr=scrp_ptr=scrp_info;
  4292.  
  4293. @* INITIALIZING the SCRAPS.  If we are going to use the powerful production
  4294. mechanism just developed, we must get the scraps set up in the first place,
  4295. given a \cee\ text. A table of the initial scraps corresponding to \cee\
  4296. tokens appeared above in the section on parsing; our goal now is to
  4297. implement that table. We shall do this by implementing a subroutine called
  4298. |C_parse| that is analogous to the |C_xref| routine used during phase one.
  4299.  
  4300. Like |C_xref|, the |C_parse| procedure starts with the current value of
  4301. |next_control| and it uses the operation |next_control=get_next()| repeatedly
  4302. to read \cee\ text until encountering the next~`\v' or comment, or until
  4303. |next_control>=formatt|. The scraps corresponding to what it reads are
  4304. appended into the |cat| and |trans| arrays, and |scrp_ptr| is advanced.
  4305.  
  4306. @<Part 2@>=@[
  4307.  
  4308. SRTN C_parse FCN((mode0)) /* Creates scraps from \cee\ tokens */
  4309.     PARSING_MODE mode0 C1("")@;
  4310. {
  4311. name_pointer p; // Identifier designator.
  4312. LANGUAGE language0 = language; // Save the incoming language.
  4313. PARSE_PARAMS parse_params0;
  4314. boolean scanning_meta = NO;
  4315.  
  4316. parse_params0 = parse_params; // Save parsing state.
  4317.  
  4318. parsing_mode = mode0;
  4319.  
  4320. if(parsing_mode == INNER)
  4321.     { // Start fresh for parsing interior code.
  4322.     at_beginning = YES;
  4323.     preprocessing = NO;
  4324.     }
  4325.  
  4326. while (next_control<formatt) 
  4327.     {
  4328.     @<Append the scrap appropriate to |next_control|@>;
  4329.     next_control = get_next();
  4330.  
  4331.     if (next_control==@'|' || next_control==begin_comment) 
  4332.         break;
  4333.  
  4334.     if(next_control == begin_language && !ok_to_define 
  4335.             && parsing_mode == OUTER)
  4336.         return;
  4337.     }
  4338.  
  4339. /* If the language has changed, append stuff to restore it. */
  4340. if(language != language0)
  4341.     {
  4342.     app_tok(begin_language);
  4343.     app(lan_num(language0));
  4344.     app_scrap(ignore_scrap,no_math);
  4345.     }
  4346.  
  4347. if(parsing_mode == INNER)
  4348.     parse_params = parse_params0; // Restore incoming values.
  4349. }
  4350.  
  4351. @ The following macro is used to append a scrap whose tokens have just
  4352. been appended.  Note that mathness is stored in the form $4(\hbox{\it right
  4353. boundary}) + \hbox{\it left boundary}$.  Thus, noting that $5b = 4b + b$,
  4354. we see that the construction~$5b$ makes the left- and right-hand boundaries
  4355. equal. 
  4356.  
  4357. @d app_scrap(c,b)@/
  4358.     (++scrp_ptr)->cat = (eight_bits)(c); 
  4359.     scrp_ptr->trans = text_ptr;
  4360.     scrp_ptr->mathness = (eight_bits)(5*(b)); /* Make left and right
  4361.         boundaries equal. */  
  4362.     freeze_text@;
  4363.  
  4364. @<Part 2@>=@[
  4365.  
  4366. SRTN set_language FCN((language0))
  4367.     LANGUAGE language0 C1("")@;
  4368. {
  4369. char language_line[50];
  4370.  
  4371. language = language0;
  4372.  
  4373. app_tok(begin_language);
  4374. app(lan_num(language));
  4375.  
  4376. if(parsing_mode == OUTER)
  4377.     {
  4378.     sprintf(language_line,"\\LANGUAGE{%s}",LANGUAGE_CODE(language));
  4379.     APP_STR(language_line);
  4380. @.\\LANGUAGE@>
  4381.     }
  4382.  
  4383. app_scrap(language_scrap,no_math);
  4384. }
  4385.  
  4386. @ Operator overloading.
  4387. @<Glob...@>=
  4388.  
  4389. EXTERN boolean overloaded[NUM_LANGUAGES];
  4390.  
  4391. EXTERN BUF_SIZE op_entries; /* Length for dynamic array. */
  4392. EXTERN OPERATOR HUGE *op, HUGE *op_end; /* Dynamic array of entries for
  4393.             operator overloading. */ 
  4394. EXTERN OPERATOR HUGE *op_ptr; /* Next open position in |OP|. */
  4395.  
  4396. @ Initializing operators is conveniently handled by macros. 
  4397.  
  4398. /* Initialize an ordinary operator such as~`\.+'. */
  4399. @d INIT_OP(op_code,op_name,lang,op_macro,cat) 
  4400.     init_op((eight_bits)(op_code),OC(op_name),(int)(lang),OC(op_macro),
  4401.         NO,cat,(CONST outer_char *)NULL)
  4402.  
  4403. /* Initialize a compound assignment operator such as~`\.{+=}'. */
  4404. @d INIT_CA(ca_index,op_name,lang,op_macro,cat)
  4405.     assignment_token = ca_index;
  4406.     INIT_OP(compound_assignment,OC(op_name),(int)(lang),OC(op_macro),cat)@;
  4407.  
  4408. /* Initialize a dot operator such as~`\.{.NE.}'. */
  4409. @d INIT_DOT(op_name,lang,op_macro,cat)
  4410.        init_op((eight_bits)identifier,OC(op_name),(int)(lang),OC(op_macro),
  4411.         NO,cat,(CONST outer_char *)NULL)
  4412.  
  4413. @d ALL_LANGUAGES ((int)C | (int)C_PLUS_PLUS | (int)FORTRAN | (int)FORTRAN_90 
  4414.     | (int)(RATFOR) | (int)(RATFOR_90) | (int)LITERAL)
  4415.  
  4416. @d ONLY_C ((int)C | (int)C_PLUS_PLUS)
  4417. @d ALL_BUT_C (~ONLY_C)
  4418.  
  4419. @<Alloc...@>=
  4420. {
  4421. int l;
  4422.  
  4423. for(l=0; l<NUM_LANGUAGES; l++)
  4424.     overloaded[l] =NO;
  4425.  
  4426. ALLOC(OPERATOR,op,ABBREV(op_entries),op_entries,0);
  4427. op_end = op + op_entries;
  4428. op_ptr = op + 128; /* The first 128 are for direct indexing. */
  4429.  
  4430. @<Initialize ordinary operators@>;
  4431. @<Initialize compound assignment operators@>;
  4432. }
  4433.  
  4434. @
  4435. @<Initialize ordinary op...@>=
  4436.  
  4437.  INIT_OP(@'!',"NOT",ALL_LANGUAGES,"\\WR",unop); // `|!|'
  4438.  INIT_DOT("NOT",ALL_BUT_C,"\\WR",unop);
  4439. @.\\WR@> @..NOT.@>
  4440.  
  4441.  INIT_OP(@'%',"MOD",ALL_LANGUAGES,"\\MOD",binop); // `|%|'
  4442. @.\\MOD@>
  4443.  
  4444.  INIT_OP(@'&',"LAND",ONLY_C,"\\amp",unorbinop);  /* `|&|'.  Among other things,
  4445.     making this a |unorbinop| lets us handle~'\.*' and~'\.\&'
  4446.     symmetrically in \Cpp. */ 
  4447. @.\\amp@>
  4448.  INIT_OP(@'&',"LAND",ALL_BUT_C,"\\AND",binop); // `|@r &|'
  4449. @.\\AND@>
  4450.  
  4451.  INIT_OP(@'*',"STAR",ALL_LANGUAGES,"\\ast",unorbinop); // `|*|'
  4452. @.\\ast@>
  4453.  INIT_OP(@'+',"PLUS",ALL_LANGUAGES,"+",unorbinop); // `|+|'
  4454.  INIT_OP(@'-',"MINUS",ALL_LANGUAGES,"-",unorbinop); // `|-|'
  4455.  INIT_OP(@'/',"SLASH",ALL_LANGUAGES,"/",binop); // `|/|'
  4456.  
  4457.  INIT_OP(@'<',"LT",ALL_LANGUAGES,"<",binop); // `|<|'
  4458.  INIT_DOT("LT",ALL_BUT_C,"<",binop);
  4459. @..LT.@>
  4460.  
  4461.  INIT_OP(@'=',"EQUALS",ALL_LANGUAGES,"=",binop); // `|=|'
  4462.  
  4463.  INIT_OP(@'>',"GT",ALL_LANGUAGES,">",binop); // `|>|'
  4464.  INIT_DOT("GT",ALL_BUT_C,">",binop);
  4465. @..GT.@>
  4466.  
  4467.  INIT_OP(@'?',"QUESTION",ONLY_C,"\\?",question); // `|?|'
  4468. @.\\?@>
  4469.  INIT_OP(@'^',"CARET",ALL_LANGUAGES,"\\^",binop); // `|x^y|'
  4470. @.\\\^@>
  4471.  
  4472.  INIT_OP(@'|',"OR",ALL_LANGUAGES,"\\OR",binop); // `$\OR$'
  4473. @.\\OR@>
  4474.  INIT_OP(@'~',"TILDE",ONLY_C,"\\TLD",unop);
  4475. @.\\TL@>
  4476.  
  4477.  INIT_OP(not_eq,"NE",ALL_LANGUAGES,"\\WI",binop);  /* `|!=|' */
  4478.  INIT_DOT("NE",ALL_BUT_C,"\\WI",binop);
  4479. @.\\WI@> @..NE.@>
  4480.  
  4481.  INIT_OP(lt_eq,"LE",ALL_LANGUAGES,"\\WL",binop);   /* `|<=|' */ 
  4482.  INIT_DOT("LE",ALL_BUT_C,"\\WL",binop);
  4483. @.\\WL@> @..LE.@>
  4484.  
  4485.  INIT_OP(gt_eq,"GE",ALL_LANGUAGES,"\\WG",binop);  /* `|>=|' */ 
  4486.  INIT_DOT("GE",ALL_BUT_C,"\\WG",binop);
  4487. @.\\WG@>
  4488.  
  4489.  INIT_OP(eq_eq,"EQ",ALL_LANGUAGES,"\\WS",binop);  /* `|==|' */
  4490.  INIT_DOT("EQ",ALL_BUT_C,"\\WS",binop);
  4491. @.\\WS@> @..EQ.@>
  4492.  
  4493.  INIT_OP(and_and,"AND",ALL_LANGUAGES,"\\WW",binop);  /* `|&&|' */ 
  4494.  INIT_DOT("AND",ALL_BUT_C,"\\WW",binop);
  4495. @.\\WW@> @..AND.@>
  4496.  
  4497.  INIT_OP(or_or,"OR",ALL_LANGUAGES,"\\WV",binop);  /* `||| |' */
  4498.  INIT_DOT("OR",ALL_BUT_C,"\\OR",binop);
  4499. @.\\WV@> @..OR.@>
  4500.  
  4501.  INIT_OP(plus_plus,"PP",ALL_LANGUAGES,"\\PP",unop); // `|++|'
  4502. @.\\PP@>
  4503.  INIT_OP(minus_minus,"MM",ALL_LANGUAGES,"\\MM",unop); // `|--|'
  4504. @.\\MM@>
  4505.  
  4506.  INIT_OP(minus_gt,"EQV",ONLY_C,"\\MG",binop);  /* `|->|' */
  4507. @.\\MG@>
  4508.  INIT_OP(minus_gt,"EQV",ALL_BUT_C,"\\EQV",binop);  /* `|@r .eqv.|' */
  4509.  INIT_DOT("EQV",ALL_BUT_C,"\\EQV",binop);
  4510. @.\\EQV@> @..EQV.@>
  4511.  
  4512.  INIT_OP(gt_gt, "RSHIFT",ONLY_C,"\\GG",binop); // `|>>|'
  4513. @.\\GG@>
  4514.  INIT_OP(lt_lt,"LSHIFT",ONLY_C,"\\LL",binop); // `|<<|'
  4515. @.\\LL@>
  4516.  INIT_OP(star_star,"EE",ALL_LANGUAGES,"\\EE",exp_op);  /* `\.{**}' */
  4517. @.\\EE@>
  4518.  INIT_OP(slash_slash,"SlSl",ALL_BUT_C,"\\SlSl",binop);  /* `|@r \/|' */
  4519. @.\\SlSl@>
  4520.  
  4521.  INIT_OP(ellipsis,"NEQV",ALL_BUT_C,"\\NEQV",binop); // `|@r .NEQV.|'
  4522.  INIT_DOT("NEQV",ALL_BUT_C,"\\NEQV",binop);
  4523.  INIT_DOT("XOR",ALL_BUT_C,"\\NEQV",binop);
  4524. @..NEQV.@> @..XOR.@>
  4525.  
  4526.  INIT_DOT("FALSE",ALL_BUT_C,"\\FALSE",expr); // `|@r .false.|'
  4527. @..FALSE.@>
  4528.  INIT_DOT("TRUE",ALL_BUT_C,"\\TRUE",expr)@; // `|@r .true.|'
  4529. @..TRUE.@>
  4530.  
  4531. @
  4532. @<Initialize compound...@>=
  4533.  
  4534.  INIT_CA(plus_eq,"Wcp",ALL_LANGUAGES,"\\Wcp",binop); // `|+=|'
  4535. @.\\Wcp@>
  4536.  INIT_CA(minus_eq,"Wcm",ALL_LANGUAGES,"\\Wcm",binop); // `|-=|'
  4537. @.\\Wcm@>
  4538.  INIT_CA(star_eq,"Wcs",ALL_LANGUAGES,"\\Wcs",binop); // `|*=|'
  4539. @.\\Wcs@>
  4540.  INIT_CA(slash_eq,"Wcv",ALL_LANGUAGES,"\\Wcv",binop); // `|/=|'
  4541. @.\\Wcv@>
  4542.  INIT_CA(mod_eq,"Wcd",ONLY_C,"\\Wcd",binop); // `|%=|'
  4543. @.\\Wcd@>
  4544.  INIT_CA(xor_eq,"Wcx",ONLY_C,"\\Wcx",binop); // `|^=|'
  4545. @.\\Wcx@>
  4546.  INIT_CA(and_eq,"Wca",ONLY_C,"\\Wca",binop); // `|&=|'
  4547. @.\\Wca@>
  4548.  INIT_CA(or_eq,"Wco",ONLY_C,"\\Wco",binop); // `||=|'
  4549. @.\\Wco@>
  4550.  INIT_CA(gt_gt_eq,"Wcg",ONLY_C,"\\Wcg",binop); // `|>>=|'
  4551. @.\\Wcg@>
  4552.  INIT_CA(lt_lt_eq,"Wcl",ONLY_C,"\\Wcl",binop)@; // `|<<=|'
  4553. @.\\Wcl@>
  4554.  
  4555. @ Initializing an operator involves several possibilities.  If the
  4556. operator's code is less than~128, the info is put directly into the
  4557. corresponding table position.  Otherwise, as for a new dot constant, we
  4558. search through the positions $>= 128$ and insert it at the first available
  4559. slot. 
  4560. @<Part 3@>=@[
  4561.  
  4562. SRTN init_op FCN((op_code,op_name,lang,op_macro,overload,cat,defn))
  4563.     eight_bits op_code C0("The operator")@;
  4564.     CONST outer_char op_name[] C0("Fortran-like name of the operator")@;
  4565.     int lang C0("Union of all allowable languages for this def")@;
  4566.     CONST outer_char op_macro[] C0("Default macro expansion")@;
  4567.     boolean overload C0("Do we overload?")@;
  4568.     eight_bits cat C0("Category code")@;
  4569.     CONST outer_char defn[] C1("Replacement text for overloaded macro")@;
  4570. {
  4571. OPERATOR HUGE *p;
  4572. int k,l;
  4573.  
  4574. /* The dot constants won't be in the table yet. Just put them there. */
  4575. if(op_code == identifier) p = op_ptr++; // Next free position for a dot op.
  4576. else if(!(p=valid_op(op_code)))
  4577.         {
  4578.         err_print(W,"Invalid op code %d",op_code);
  4579.         return;
  4580.         }
  4581.  
  4582. p->op_name = GET_MEM("op name",STRLEN(op_name)+1,ASCII);
  4583. STRCPY(p->op_name,op_name);
  4584. to_ASCII((outer_char *)p->op_name);
  4585.  
  4586. /* Access the languages by bit-shifting with~|l|. */
  4587. for(k=0,l=1; k<NUM_LANGUAGES; k++,l<<=1)
  4588.     if(lang & l)
  4589.         {
  4590.         OP_INFO HUGE *q = p->info + k;
  4591.  
  4592.         q->op_macro = op_macro;
  4593.         overloaded[k] |= (q->overloaded = overload);
  4594.         q->cat = cat;
  4595.         if(defn) q->defn = (outer_char HUGE *)defn;
  4596.         }
  4597. }
  4598.  
  4599. @ A storage variable.
  4600. @<Glob...@>=
  4601.  
  4602. EXTERN eight_bits last_control;
  4603.  
  4604. @ Here we translate |next_control| into text characters, which are stored
  4605. in memory.
  4606.  
  4607. @<Append the scr...@>=
  4608. {
  4609. room_for(6,4,4); // Is there enough room?  (Check and justify these numbers!!!)
  4610.  
  4611. if(next_control) lst_ampersand = NO;
  4612.  
  4613. switch (next_control) 
  4614.     {
  4615.   case macro_module_name: @<Append a module name@>@; break;
  4616.     
  4617.   case stmt_label: 
  4618.   case stringg: case constant: case verbatim: @<Append a string or constant@>;
  4619.     break;
  4620.  
  4621.   case begin_format_stmt: in_format = YES;
  4622.   case identifier: @<Append an identifier scrap@>; break;
  4623.   case TeX_string: @<Append a \TeX\ string scrap@>; break;
  4624.   case begin_language: @<Append scraps for |begin_language|@>; break;
  4625.  
  4626.   case new_output_file: @<Append the output file name@>@; break;
  4627.  
  4628.   case toggle_output:
  4629.     @<Toggle output@>@;
  4630.     @<Store output switch and \.{\\Wskipped}@>@;
  4631.     break; 
  4632.  
  4633.   case macro_space: app(@' '); app_scrap(space,maybe_math); break;
  4634.  
  4635.   @<Cases involving single ASCII characters@>@:@;
  4636.   @<Cases involving nonstandard ASCII characters@>@:@;
  4637.   @<Cases involving special \WEB\ commands@>@:@;
  4638.  
  4639.   default: app(next_control); app_scrap(ignore_scrap,maybe_math); break;
  4640.     }
  4641. }
  4642.  
  4643. @ Check against possible overflow.
  4644.  
  4645. @<Part 3@>=@[
  4646.  
  4647. SRTN room_for FCN((ntokens,ntexts,nscraps))
  4648.     int ntokens C0("")@;
  4649.     int ntexts C0("")@;
  4650.     int nscraps C1("")@;
  4651. {
  4652. if(tok_ptr+ntokens>tok_m_end)
  4653.     {
  4654.     if (tok_ptr>mx_tok_ptr) mx_tok_ptr=tok_ptr;
  4655.     OVERFLW("tokens",ABBREV(max_toks_w));
  4656.     }
  4657.  
  4658. if(text_ptr+ntexts>tok_end) 
  4659.     {
  4660.     if (text_ptr>mx_text_ptr) mx_text_ptr=text_ptr;
  4661.     OVERFLW("texts",ABBREV(max_texts));
  4662.     }
  4663.  
  4664. if (scrp_ptr+nscraps>scrp_end)
  4665.     {
  4666.     if (scrp_ptr>mx_scr_ptr) mx_scr_ptr=scrp_ptr;
  4667.     OVERFLW("scraps",ABBREV(max_scraps));
  4668.     }
  4669. }
  4670.  
  4671. @ Some nonstandard ASCII characters may have entered \.{WEAVE} by means of
  4672. standard ones. They are converted to \TeX\ control sequences so that it is
  4673. possible to keep \.{WEAVE} from stepping beyond standard ASCII.
  4674.  
  4675. @<Cases involving nonstandard...@>=
  4676.  
  4677. /* Overloaded operators can be defined dynamically in \FORTRAN-88. These
  4678. are generically labelled by |dot_const|. The |dot_code| routine fills the
  4679. structure |dot_op| with the macro name and category corresponding to the
  4680. operator. */
  4681. case dot_const: 
  4682.     next_control = identifier;
  4683.     id_first = dot_op.name + 1;
  4684.     id_loc = id_first + STRLEN(id_first);
  4685.     app_overload();
  4686.     break;
  4687.  
  4688. case eq_gt: APP_STR("\\WPtr"); /* `$\WPtr$' */ app_scrap(binop,yes_math);
  4689. break; 
  4690. @.\\WPtr@>
  4691.  
  4692. case ellipsis: 
  4693.     if(C_LIKE(language))
  4694.         {
  4695.         APP_STR("\\dots"); /* `|...|' */
  4696. @.\\dots@>
  4697.         app_scrap(int_like,maybe_math);
  4698.         }
  4699.     else app_overload();
  4700.  
  4701.     break;
  4702.  
  4703. case not_eq: 
  4704. case lt_eq: 
  4705. case gt_eq: 
  4706. case eq_eq: 
  4707. case and_and: 
  4708. case or_or: 
  4709. case plus_plus:
  4710. case minus_minus:
  4711. case minus_gt:
  4712. case gt_gt: 
  4713. case lt_lt:
  4714. case star_star: 
  4715. case slash_slash: 
  4716. case compound_assignment:
  4717.     app_overload(); @+ break;
  4718.  
  4719. case paste: APP_STR("\\NN"); /* `|##|' */ app_scrap(ignore_scrap,maybe_math);
  4720.             break;
  4721. @.\\NN@>
  4722.  
  4723. case dont_expand: APP_STR("\\NP"); /* `|#!|' */
  4724.         app_scrap(ignore_scrap,maybe_math); 
  4725.             break;
  4726. @.\\NP@>
  4727.  
  4728. case auto_label: APP_STR("\\NC"); /* `|#:|' */
  4729.         app_scrap(ignore_scrap,maybe_math); 
  4730.         break;
  4731. @.\\NC@>
  4732.  
  4733. case all_variable_args: 
  4734.     APP_STR("\\ND"); // `|#.|
  4735.     app_scrap(expr,maybe_math);
  4736.     break;
  4737. @.\\ND@>
  4738.  
  4739. case colon_colon: 
  4740.     if(C_LIKE(language))
  4741.         {
  4742. @.\\CC@>
  4743.         APP_STR("\\CC"); // `|a::b|'
  4744.         app_scrap(unop,yes_math);
  4745.         }
  4746.     else
  4747.         {
  4748.         APP_STR("\\CF"); // `|@r a::b|'
  4749. @.\\CF@>
  4750.         app_scrap(binop,yes_math);
  4751.         }
  4752.     break;
  4753.  
  4754. case left_array:
  4755.     APP_STR("\\LS"); // `|@r (/|'
  4756. @.\\LS@>
  4757.     app_scrap(lpar,yes_math);
  4758.     break;
  4759.  
  4760. case right_array:
  4761.     APP_STR("\\SR"); // `|@r /)|'
  4762. @.\\SR@>
  4763.     app_scrap(rpar,yes_math);
  4764.     break;
  4765.  
  4766. @
  4767. @<Cases involving special...@>=
  4768.  
  4769.   case force_line: APP_STR("\\]"); app_scrap(ignore_scrap,yes_math); break;
  4770.   case thin_space: APP_STR("\\,"); app_scrap(ignore_scrap,yes_math); break;
  4771.   case math_break: app(opt); @+ APP_STR("0");
  4772.             app_scrap(ignore_scrap,yes_math); break; 
  4773.   case line_break: app(force); app_scrap(ignore_scrap,no_math); break;
  4774.  
  4775.   case left_preproc: 
  4776.     app(force);
  4777.     if(parsing_mode==OUTER) APP_STR("\\4"); // Backspace for beauty.
  4778.     app_scrap(lproc,no_math); break;
  4779.  
  4780.   case right_preproc: 
  4781.     app(force); app_scrap(rproc,no_math); break;
  4782.  
  4783.   case no_mac_expand:
  4784.     APP_STR("\\WTLD"); app_scrap(expr,maybe_math); break;
  4785.  
  4786.   case begin_meta: 
  4787.     @<Process |begin_meta|@>@;
  4788.     break;
  4789.  
  4790.   case end_meta:
  4791.     if( !nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input) 
  4792.             || (language==TEX)) )  
  4793.         @<Set up column mode@>@;
  4794.  
  4795.     get_line();
  4796.     APP_STR(w_style.misc.meta.code.end); 
  4797.     app(force);
  4798.     app_scrap(ignore_scrap,no_math); 
  4799.     scanning_meta = NO;
  4800.     break;
  4801.  
  4802. @.\\WBM@>
  4803. @.\\WEM@>
  4804.  
  4805.   case big_line_break: app(big_force); app_scrap(ignore_scrap,no_math); break;
  4806.   case no_line_break: app(big_cancel); @+ APP_STR("\\ ");@+ app(big_cancel);
  4807.     app_scrap(ignore_scrap,no_math); break;
  4808.  
  4809.   case pseudo_expr: app_scrap(expr,maybe_math); @+ break;
  4810.   case pseudo_semi: app_scrap(semi,maybe_math); @+ break;
  4811.   case pseudo_colon: app_scrap(colon,maybe_math); @+ break;
  4812.  
  4813.   case join: APP_STR("\\WJ"); app_scrap(ignore_scrap,no_math); break;
  4814. @.\\WJ@>
  4815.  
  4816. @
  4817. @<Process |begin_meta|@>=
  4818. {
  4819. if(!nuweb_mode)
  4820.     app(force);
  4821.  
  4822. APP_STR(w_style.misc.meta.code.begin); 
  4823.  
  4824. column_mode = NO;
  4825. scanning_meta = YES;
  4826.  
  4827. WHILE()
  4828.     {
  4829.     if(loc >= limit) // !!!!!
  4830.         if(!get_line()) break;
  4831.  
  4832.     while(loc < limit) 
  4833.         {
  4834.         if(*loc == @'@@') 
  4835.             @<Check for end of meta-comment and |goto
  4836. done_meta| if necessary@>@; 
  4837.         app(*loc++);
  4838.         }
  4839.  
  4840.     app(@'\n');
  4841.     }
  4842.  
  4843. done_meta:
  4844.     APP_STR(w_style.misc.meta.code.end); 
  4845.     if(!nuweb_mode)
  4846.         app(force);
  4847.     app_scrap(ignore_scrap,no_math); 
  4848.     scanning_meta = NO;
  4849. }
  4850.  
  4851. @
  4852. @<Check for end of meta-comment...@>=
  4853. {
  4854. switch(ccode[*(loc+1)])
  4855.     {
  4856.    case end_meta:
  4857.     if( !nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input) 
  4858.             || (language==TEX)) )  
  4859.         @<Set up column mode@>@;
  4860.  
  4861.     get_line();
  4862.     goto done_meta;
  4863.  
  4864.    case invisible_cmnt:
  4865.     if(*(loc+2) == @'%')
  4866.         eat_blank_lines = YES;
  4867.  
  4868.     get_line();
  4869.  
  4870.     if(eat_blank_lines)
  4871.         {
  4872.         eat_blank_lines = NO;
  4873.  
  4874.         while(loc >= limit)
  4875.             if(!get_line())
  4876.                 goto done_meta;
  4877.         }
  4878.  
  4879.     continue;
  4880.     
  4881.    case new_module:
  4882.     goto done_meta; // !!!!!
  4883.  
  4884.     case thin_space: 
  4885.     case line_break: case no_line_break: case join:
  4886.     case pseudo_semi: case pseudo_expr: case pseudo_colon:
  4887.     case compiler_directive: case Compiler_Directive:
  4888.     case no_index: case yes_index:
  4889.     case begin_bp: case insert_bp:
  4890.     loc += 2;
  4891.     continue;
  4892.  
  4893.    case big_line_break: 
  4894.     break; // To handle preprocessor statements easily.
  4895.  
  4896.    default:
  4897.     if(nuweb_mode)
  4898.         goto done_meta;  // !!!!!
  4899.  
  4900.       break;
  4901.     }
  4902. }
  4903.  
  4904. @
  4905. @<Cases involving single...@>=
  4906.  
  4907.   case @'\\':
  4908.     APP_STR("\\ttBS");
  4909.     app_scrap(ignore_scrap,no_math);
  4910.     break;
  4911.  
  4912.   case @'\n': 
  4913.     app(@' ');
  4914.     app_scrap(newline,maybe_math);
  4915.     break;
  4916.  
  4917.   case @'/': 
  4918.     if(in_format)
  4919.         {
  4920.         app(next_control);
  4921.         app_scrap(expr,no_math); /* ``|@r format(//e10.5/f5.2)|'' */
  4922.         }
  4923.     else if(in_data)
  4924.         {
  4925.         app(@'{'); @+ app(next_control); @+ app(@'}');
  4926.         app_scrap(slash_like,maybe_math);
  4927.         }
  4928.     else
  4929.         {
  4930.         app_overload(); /* ``|a/b|'' */
  4931.         }
  4932.     break;
  4933.  
  4934. case @'.': 
  4935.     app(next_control); app_scrap(binop,yes_math); break;
  4936.  
  4937.  case @'+':/* Handle \FORTRAN's |@r +1.0|; now also ANSI~C: ``|x = +2.5;|'' */ 
  4938.  case @'<': 
  4939.  case @'>': 
  4940.  case @'=': 
  4941.  case @'%':
  4942.  case @'!': 
  4943.  case @'~': 
  4944.  case @'-': 
  4945.  case @'*': 
  4946.  case @'|':
  4947.  case @'?':
  4948.  case @'^':
  4949.     app_overload(); @+ break;
  4950.  
  4951.  case @'&':
  4952.     lst_ampersand = YES;
  4953.     app_overload(); @+ break;
  4954.  
  4955.  case @'#': 
  4956.     switch(*loc)
  4957.         {
  4958.        case @'\'':
  4959.         APP_STR("\\Nq");
  4960.         loc++;
  4961.         break;
  4962.  
  4963.        case @'"':
  4964.         APP_STR("\\NQ");
  4965.         loc++;
  4966.         break;
  4967.  
  4968.        default:
  4969.         APP_STR("\\#");
  4970.         break;
  4971.         }
  4972.  
  4973.     app_scrap(expr,maybe_math); 
  4974.     break;
  4975.  
  4976.   case ignore: case xref_roman: case xref_wildcard:
  4977.   case xref_typewriter: break;
  4978.  
  4979.   case @'(': app(next_control); app_scrap(lpar,maybe_math); break;
  4980.   case @')': app(next_control); app_scrap(rpar,maybe_math); break;
  4981.  
  4982.   case @'[': app(next_control); app_scrap(lbracket,yes_math); break;
  4983.   case @']': app(next_control); app_scrap(rbracket,yes_math); break;
  4984.  
  4985.   case @'{': APP_STR("\\{"); app_scrap(lbrace,yes_math); break;
  4986.   case @'}': APP_STR("\\}"); app_scrap(rbrace,yes_math); break;
  4987.   case @',': app(@','); app_scrap(comma,maybe_math); break;
  4988.  
  4989.   case end_format_stmt: in_format = NO; /* Falls through to the next case,
  4990.         which appends the semi. */
  4991.   case interior_semi:
  4992.     in_data = NO;
  4993.     app(@';'); app_scrap(semi,maybe_math); break;
  4994.   case @';': 
  4995.     in_data = NO;
  4996.     if(!is_FORTRAN_(language) || prn_semis)
  4997.         app(@';');
  4998.      app_scrap(semi,maybe_math); break;
  4999.  
  5000.   case @':': app(@':'); app_scrap(colon,maybe_math);
  5001.      break;
  5002.   case @'`': 
  5003. @#if 0
  5004.     if(!ok_to_define)
  5005.         {
  5006.         APP_STR("\\LA"); app_scrap(expr,maybe_math);
  5007.         }
  5008.     else
  5009.         {
  5010.         q_protected = BOOLEAN(!q_protected);
  5011.         app(q_protected ? @'{' : @'}');
  5012.         app_scrap(expr,yes_math);
  5013.         }
  5014. @#endif
  5015.     APP_STR("\\LA"); app_scrap(expr,maybe_math);
  5016.     break;
  5017.  
  5018. @
  5019. @<Append scraps for |begin_language|@>=
  5020.  
  5021.     switch(language)
  5022.         {
  5023.       case NO_LANGUAGE:
  5024.         CONFUSION("append scraps for begin_language",
  5025.             "Language isn't defined");
  5026.  
  5027.       case C: 
  5028.       case C_PLUS_PLUS:
  5029.       case LITERAL:
  5030.         column_mode = NO; @+ break;
  5031.  
  5032.       case FORTRAN: 
  5033.       case FORTRAN_90:
  5034.       case RATFOR: 
  5035.       case RATFOR_90:
  5036.         if(mode0==OUTER && !free_form_input) @<Set up column mode@>@;
  5037.         break;
  5038.  
  5039.       case TEX:
  5040.         if(mode0==OUTER) @<Set up col...@>@;
  5041.         break;
  5042.  
  5043.        case NUWEB_OFF:
  5044.        case NUWEB_ON:
  5045.     CONFUSION("append scraps for begin_language","Invalid language");
  5046.          }
  5047.  
  5048.     set_language(language);
  5049.     break@;
  5050.  
  5051. @ The following function returns a pointer to an |OPERATOR| structure, or
  5052. |NULL| if there's something invalid about the operator.  Identifiers must
  5053. be searched for explicitly.  If an identifier isn't there, it's put into
  5054. the table.
  5055. @<Part 3@>=@[
  5056.  
  5057. OPERATOR HUGE *valid_op FCN((op_code))
  5058.     eight_bits op_code C1("")@;
  5059. {
  5060. int n = 0;
  5061. OPERATOR HUGE *p;
  5062.  
  5063. switch(op_code)
  5064.     {
  5065.    case @'/':
  5066.    case @'+':
  5067.    case @'<': 
  5068.    case @'>': 
  5069.    case @'=': 
  5070.    case @'%':
  5071.    case @'!': 
  5072.    case @'~': 
  5073.    case @'-': 
  5074.    case @'*': 
  5075.    case @'&':
  5076.    case @'|':
  5077.    case @'?':
  5078.    case @'^':
  5079.    case ellipsis:
  5080.    case not_eq: 
  5081.    case lt_eq: 
  5082.    case gt_eq: 
  5083.    case eq_eq: 
  5084.    case and_and: 
  5085.    case or_or: 
  5086.    case plus_plus:
  5087.    case minus_minus:
  5088.    case minus_gt:
  5089.    case gt_gt: 
  5090.    case lt_lt:
  5091.    case star_star: 
  5092.    case slash_slash: 
  5093.     p = op + op_code;
  5094.     if(p >= op + 128) CONFUSION("valid_op",
  5095.         "Operator out of range");
  5096.     return p;
  5097.  
  5098.    case compound_assignment:
  5099.     if(assignment_token==or_or_or)
  5100.         return op + @'|';
  5101.  
  5102.     p = op + CA_START + assignment_token;
  5103.     if(p >= op + 128) CONFUSION("valid_op",
  5104.         "Compound assignment operator out of range");
  5105.     return p;
  5106.  
  5107.    case dot_const:
  5108.     if(!FORTRAN_LIKE(language)) return NULL;
  5109.     id_first = dot_op.name + 1;
  5110.     id_loc = id_first + STRLEN(id_first);
  5111.  
  5112.    case identifier:
  5113.     if(!FORTRAN_LIKE(language)) return NULL; /* Can do names only in
  5114. \Fortran. */ 
  5115.     @<Add an operator to the table, if necessary, and |return p|@>@; 
  5116.     }
  5117.  
  5118. return NULL;
  5119. }        
  5120.  
  5121. @
  5122. @<Add an operator...@>=
  5123. {
  5124. ASCII id[255];
  5125.  
  5126. STRNCPY(id,id_first,n=id_loc-id_first);
  5127. id[n] = '\0'; // Make into proper string.
  5128.  
  5129. for(p=op+128; p<op_ptr; p++)
  5130.     if(STRCMP(p->op_name,id) == 0) return p;
  5131.  
  5132. if(op_ptr >= op_end) OVERFLW("op table","op");
  5133.  
  5134. p->op_name = GET_MEM("op name",n+1,ASCII);
  5135. STRCPY(p->op_name,id);
  5136. op_ptr++;
  5137. return p;
  5138. }
  5139.  
  5140. @ The form in which operators are appended depends on whether they have
  5141. been overloaded with an \.{@@v}~command or not.  If they have not, they are
  5142. are appended as a straight macro name, such as the translation of
  5143. `\.{.FALSE.}' into `\.{\\FALSE}'.  If they have been overloaded, they are
  5144. appended instead as a construction such as `\.{\\Wop\{FALSE\}\{N\}}';
  5145. the output limbo section will then contain an automatically generated
  5146. definition such as `\.{\\newop\{FALSE\}\{N\}\{\\\{.FALSE.\}\}}'. This
  5147. defines the macro \.{\\\_FALSE\_N} to have the definition specified in the
  5148. \.{@@v}~command. 
  5149.  
  5150. @<Part 3@>=@[
  5151.  
  5152. SRTN app_overload(VOID)
  5153. {
  5154. int ln = language_num;
  5155. OPERATOR HUGE *p = valid_op(next_control);
  5156. OP_INFO HUGE *q = p->info + ln;
  5157. char temp[10];
  5158.  
  5159. if(overload_ops && q->overloaded)
  5160.     {
  5161.     switch(q->cat)
  5162.         {
  5163.         case unorbinop:
  5164.         case binop:
  5165.             APP_STR("\\Wb{"); @+ break;
  5166.  
  5167.         case unop:
  5168.             APP_STR("\\Wu{"); @+ break;
  5169.  
  5170.         default:
  5171.             APP_STR(" \\Wop{"); @+ break;
  5172.         }
  5173.  
  5174.     app_ASCII_str(p->op_name);
  5175.     sprintf(temp,"}{%s}",lang_codes[ln]);
  5176.     APP_STR(temp);
  5177.     }
  5178. else if(q->op_macro) 
  5179.     APP_STR(q->op_macro);
  5180. else
  5181.     {
  5182.        err_print(W,"Unidentifiable dot constant in language %s.  Missing @@v?",
  5183.         languages[ln]);
  5184.     APP_STR("\\Wunknown{");
  5185.     app(wt_style.dot_delimiter.begin);
  5186.     app_ASCII_str(p->op_name);
  5187.     app(wt_style.dot_delimiter.end);
  5188.     app(@'}');
  5189.     app_scrap(binop,yes_math);
  5190.     return;
  5191.     }
  5192.  
  5193. app_scrap(q->cat,yes_math);
  5194. }
  5195.  
  5196. @ The following code must use |app_tok| instead of |app| in order to
  5197. protect against overflow. Note that |tok_ptr+1<=max_toks| after |app_tok|
  5198. has been used, so another |app| is legitimate before testing again.
  5199.  
  5200. Many of the special characters in a string must be prefixed by '\.\\' so that
  5201. \TeX\ will print them properly.
  5202. @^special string characters@>
  5203.  
  5204. @<Append a string or...@>=
  5205.  
  5206. if(next_control == stmt_label && !isDigit(*id_first)) /* Identifier as
  5207.                 statement label. */
  5208.     {
  5209.     p = id_lookup(id_first,id_loc,normal);
  5210.     APP_FLAG(id,p,name_dir);
  5211.     app_scrap(label,no_math);
  5212.     }
  5213. else
  5214.     {
  5215.     if (next_control==constant || next_control==stmt_label) 
  5216.         APP_STR("\\WO{");
  5217. @.\\WO@>
  5218.     else if (next_control==stringg)
  5219.         @<Append commands for beginning of string@>@;
  5220. @.\\.@>
  5221.     else APP_STR("\\={");
  5222. @.\\=@>
  5223.  
  5224.     @<Append the basic string@>@;
  5225.  
  5226.     if(next_control==stmt_label) {app_scrap(label,no_math);}
  5227.     else {app_scrap(expr,yes_math);}
  5228.     }
  5229.  
  5230. @
  5231. @<Append commands for beginning of string@>=
  5232. {
  5233. APP_STR(pfmt->typewritr);
  5234. app_tok(@'{');
  5235. }
  5236.  
  5237. @ Here we append the string material within [|id_first|,|id_loc|).  This is
  5238. basically straightforward; however, commas are replaced by~`\.{\\1}' (which
  5239. will be treated as a comma followed by a discretionary break), the
  5240. |discretionary_break| code is replaced by~`\.{\\2}' (which will be treated
  5241. as a discretionary break), the |ordinary_space| code is replaced
  5242. by~`\.{\\2}' (which is treated as an ordinary space, not~`\.{\ }'), and the
  5243. |tab_mark| code (which will be present only in \TeX\ mode) is replaced
  5244. by~`\.{\\3}', which is defined in \.{fwebmac.web} to be several spaces.
  5245.  
  5246. @<Append the basic str...@>=
  5247. {
  5248. while (id_first<id_loc) 
  5249.     {
  5250.       switch (*id_first) 
  5251.         {
  5252.     case @',': *id_first = @'1'; app(@'\\'); break; 
  5253.  
  5254.     case ordinary_space:
  5255.         *id_first = @'2'; app(@'\\'); break;
  5256.  
  5257.     case tab_mark:
  5258.         *id_first = @'3'; app(@'\\'); break;
  5259.  
  5260.     case discretionary_break: *id_first = @'0'; // Falls through!
  5261.  
  5262.     @<Special string cases@>:
  5263.         app(@'\\'); break;
  5264.  
  5265.     case @'@@': if (*(id_first+1)==@'@@') id_first++;
  5266.           else ERR_PRINT(W,"Double @@ should be used in strings");
  5267. @.Double \AT! should be used...@>
  5268.           }
  5269.  
  5270.       app_tok(*id_first++);
  5271.     }
  5272.  
  5273. /* End the macro. */
  5274. app(@'}'); 
  5275. }
  5276.  
  5277. @ Here are the characters that are special to \TeX\ and therefore need to
  5278. be escaped within a string.
  5279.  
  5280. @f @<Special string cases@> default
  5281. @f @<Special \TeX\ cases@> default
  5282. @f @<Other string cases@> default
  5283.  
  5284. @<Special string cases@>=
  5285.  
  5286. @<Special \TeX\ cases@>:
  5287. @<Other string cases@>@: @;
  5288.  
  5289. @
  5290. @<Special \TeX\ cases@>=
  5291.  
  5292. case @'\\':case @'{': case @'}'@: @;
  5293.  
  5294. @
  5295. @<Other string cases@>=
  5296. case @' ':case @'#':case @'%':case @'$':case @'^':case @'`':
  5297. case @'~': case @'&': case @'_'@: @;
  5298.  
  5299. @ This fragment appends the text collected inside `\.{@@t\dots@@>}'.  That
  5300. text is placed inside an \.{\\hbox} and treated as an ordinary expression.
  5301.  
  5302. @<Append a \TeX\ string scrap@>=
  5303.  
  5304. APP_STR("\\hbox{"); while (id_first<id_loc) app_tok(*id_first++);
  5305. app(@'}'); app_scrap(expr,maybe_math);
  5306.  
  5307. @ Ordinary identifiers are just treated as expressions.
  5308.  
  5309. @<Append an identifier scrap@>=
  5310.  
  5311. p = id_lookup(id_first, id_loc,normal);
  5312.  
  5313. @#if 0
  5314. if (p->ilk==normal || !(p->reserved_word & (boolean)language) ) 
  5315.     {
  5316.     APP_FLAG(id,p,name_dir);
  5317.     app_scrap(expr,maybe_math); /* not a reserved word */
  5318.     }
  5319. else 
  5320.     {
  5321.     APP_FLAG(res,p,name_dir);
  5322.     app_scrap(p->ilk,maybe_math);
  5323.     }
  5324. @#endif
  5325.  
  5326. if(p->wv_macro)
  5327.     {
  5328.     WV_MACRO HUGE *w = p->wv_macro;
  5329.     ASCII HUGE *s = w->text;
  5330.  
  5331.     if(w->cat) 
  5332.         {
  5333.         APP_STR(pfmt->id);
  5334.         app(@'{');
  5335.         }
  5336.  
  5337.     while(*s)
  5338.         app_tok(*s++);
  5339.  
  5340.     if(w->cat) app(@'}');
  5341.     
  5342.     app_scrap(p->ilk ? p->ilk : expr, w->cat ? maybe_math : yes_math);
  5343.     }
  5344. else if (p->reserved_word & (boolean)language)
  5345.      {
  5346.     APP_FLAG(res,p,name_dir);
  5347.     app_scrap(p->ilk == normal ? expr : p->ilk,maybe_math);
  5348. /* See the inverse construction in \.{reserved}:|save_words|. */
  5349.     }
  5350. else
  5351.     {
  5352.     APP_FLAG(id,p,name_dir);
  5353.     app_scrap(expr,maybe_math); // Not a reserved word.
  5354.     }
  5355.  
  5356. @
  5357. @<Append the output file...@>=
  5358. {
  5359. APP_STR(upper_case_code ? "\\WOut{" : "\\Wout{");
  5360.     *id_loc = '\0';
  5361.     id_first = esc_buf(mod_text+1, mod_end, id_first, YES);
  5362.      was_opened(id_first, upper_case_code, ¶ms.OUTPUT_FILE_NAME, NULL);
  5363.     if(upper_case_code)
  5364.         was_opened(id_first, upper_case_code,
  5365.             &global_params.OUTPUT_FILE_NAME, NULL); 
  5366.     while(*id_first) 
  5367.         app_tok(*id_first++);
  5368. app(@'}');
  5369.  
  5370. @%if(nuweb_mode)
  5371.     app(force);
  5372.  
  5373. app_scrap(ignore_scrap,no_math);
  5374.  
  5375. if(nuweb_mode)
  5376.     { /* !!!!! */
  5377.     next_control = begin_meta;
  5378.     continue;
  5379.     }
  5380. }
  5381.  
  5382. @ When the~`\vertbar' that introduces \cee\ text is sensed, a call on
  5383. |C_translate| will return a pointer to the \TeX\ translation of that text.
  5384. If scraps exist in |scrp_info|, they are unaffected by this translation
  5385. process.
  5386.  
  5387. @<Part 2@>=@[
  5388.  
  5389. text_pointer C_translate(VOID)
  5390. {
  5391. text_pointer p; // Points to the translation.
  5392. scrap_pointer save_base; // Holds original value of |scrp_base|.
  5393. PARAMS outer_params;
  5394.  
  5395. outer_params = params;
  5396. save_base = scrp_base; 
  5397. scrp_base = scrp_ptr+1; // Empty work space after last existing scrap.
  5398.  
  5399. /* We enclose code fragments with the \TeX\ macro~\.{\\WCD\{\dots\}}. */
  5400. APP_STR("\\WCD{"); app_scrap(ignore_scrap,no_math);
  5401.  
  5402. while(next_control <= module_name)
  5403.     {
  5404.     C_parse(INNER); // Get the scraps together.
  5405.  
  5406.     if(next_control == @'|') 
  5407.         break;
  5408.  
  5409.     @<Emit the scrap for a module name if present@>;
  5410.  
  5411.     if(next_control == @'|') 
  5412.         break;
  5413.     }
  5414.  
  5415. app_tok(cancel); app_scrap(ignore_scrap,maybe_math);
  5416.     // Place a |cancel| token as a final ``comment''.
  5417.  
  5418. app(@'}'); app_scrap(ignore_scrap,no_math);
  5419.  
  5420. if (next_control != @'|') 
  5421.     ERR_PRINT(W,"Missing '|' after code text");
  5422. @.Missing '|'...@>
  5423.  
  5424. p = translate(INNER); // Make the translation.
  5425.  
  5426. if (scrp_ptr>mx_scr_ptr) 
  5427.     mx_scr_ptr=scrp_ptr;
  5428.  
  5429. scrp_ptr = scrp_base-1; // Restore old |scrp_ptr|.
  5430. scrp_base = save_base; // Scrap the scraps.
  5431. params = outer_params;
  5432. frz_params();
  5433.  
  5434. return p;
  5435. }
  5436.  
  5437. @ The |outr_parse| routine is to |C_parse| as |outr_xref| is to |C_xref|:
  5438. it constructs a sequence of scraps for \cee\ text until
  5439. |next_control>=formatt|. Thus, it takes care of embedded comments.
  5440.  
  5441. @<Part 2@>=@[
  5442.  
  5443. SRTN outr_parse(VOID) /* makes scraps from \cee\ tokens and comments */
  5444. {
  5445.   int bal; // Brace level in comment.
  5446.   text_pointer p, q; // Partial comments.  |p|: Stuff before `\Cb'; |q|: `\Cb'.
  5447.  
  5448.   while (next_control<formatt)
  5449.     {
  5450.     if (next_control != begin_comment) 
  5451.     C_parse(OUTER);
  5452.     else 
  5453.     @<Append a comment or compiler directive@>@;
  5454.     }
  5455. }
  5456.  
  5457. @
  5458. @<Append a comment...@>=
  5459. { // Append a comment/compiler directive.
  5460. if(doing_cdir) 
  5461.     @<Begin a compiler directive@>@;
  5462. else 
  5463.     @<Append a regular comment@>@;
  5464.  
  5465. bal = copy_comment(1);  // Closing brace is inserted here.
  5466. next_control = ignore;
  5467.  
  5468. if(doing_cdir && bal > 0) 
  5469.     ERR_PRINT(W,"Can't have vertical bars in @@! compiler directives");
  5470.  
  5471. doing_cdir = NO;
  5472.  
  5473. /* Handle code mode inside comments. */
  5474. while (bal > 0) 
  5475.     {
  5476.     in_comment = YES;
  5477.     p=text_ptr; freeze_text; 
  5478.  
  5479.     q = C_translate();
  5480.              /* at this point we have |tok_ptr+7<=max_toks| */
  5481.     APP_FLAG(tok,p,tok_start); APP_FLAG(inner_tok,q,tok_start);
  5482.  
  5483.         if (next_control==@'|') 
  5484.         {
  5485.           bal = copy_comment(bal);
  5486.           next_control = ignore;
  5487.         }
  5488.         else 
  5489.         bal = 0; // An error has been reported.
  5490.     }
  5491.  
  5492.  app(force); app_scrap(ignore_scrap,no_math); /* the full comment
  5493.                     becomes a scrap */ 
  5494. }
  5495.  
  5496. @ Compiler directives are begun by the style-file text \.{cdir.start}.  For
  5497. example, `\.{@@!abc}' $\to$ `\.{\#pragma\ abc}'.
  5498.  
  5499. @<Begin a compiler dir...@>=
  5500. {
  5501. outer_char HUGE *s = t_style.cdir_start[language_num];
  5502. int n = 2*STRLEN(s); // The factor of~2 counts possible escapes.
  5503. ASCII HUGE *temp = GET_MEM("temp_cdir",n+1,ASCII);
  5504. ASCII HUGE *start = GET_MEM("start_cdir",n+1,ASCII);
  5505.  
  5506. STRCPY(start,s);
  5507. to_ASCII((outer_char HUGE *)start);
  5508.  
  5509. room_for(9+n,3,1); /* Tokens: */
  5510.  
  5511. app(force);
  5512. APP_STR("\\WCDIR{");
  5513. esc_buf(temp,temp+n,start,YES); @+ APP_STR(to_outer(temp));
  5514. @.\\WCDIR@>
  5515. FREE_MEM(temp,"temp_cdir",n+1,ASCII);
  5516. FREE_MEM(start,"start_cdir",n+1,ASCII);
  5517. }
  5518.  
  5519. @
  5520. @<Append a regular comment@>=
  5521. {
  5522. room_for(8,3,1); /* Tokens:  `\.{;{ }\ { }\\{ }W{ }C\{{ }\}{ }\It{force}}'. */
  5523.  
  5524. if(Fortran88)
  5525.     {
  5526.     if(free_Fortran && lst_ampersand)
  5527.         {
  5528.         scrp_ptr--; // Kill off the \.{\&}.
  5529.         }
  5530.     else if(!at_beginning && auto_semi)
  5531.         {
  5532.         app(@';');
  5533.         }
  5534.     last_was_cmnt = YES;
  5535.     }
  5536.  
  5537. app(break_space); 
  5538. APP_STR(long_comment ? "\\WC{" : "\\Wc{"); // Long/short comment.
  5539. @.\\WC@> @.\\Wc@>
  5540. }
  5541.  
  5542. @* OUTPUT of TOKENS.  So far our programs have only built up multi-layered
  5543. token lists in \.{WEAVE}'s internal memory; we have to figure out how to
  5544. get them into the desired final form. The job of converting token lists to
  5545. characters in the \TeX\ output file is not difficult, although it is an
  5546. implicitly recursive process. Three main considerations had to be kept in
  5547. mind when this part of \.{WEAVE} was designed: (a)~There are two modes of
  5548. output, |outer| mode that translates tokens like |force| into line-breaking
  5549. control sequences, and |inner| mode, intended for code between~\Cb, that
  5550. ignores them except that blank 
  5551. spaces take the place of line breaks. (b)~The |cancel| instruction applies
  5552. to adjacent token or tokens that are output, and this cuts across levels of
  5553. recursion since `|cancel|' occurs at the beginning or end of a token list
  5554. on one level. (c)~The \TeX\ output file will be semi-readable if line
  5555. breaks are inserted after the result of tokens like |break_space| and
  5556. |force|.  (d)~The final line break should be suppressed, and there should
  5557. be no |force| token output immediately after `\.{\\WY\\WP}'.
  5558.  
  5559. @i output.hweb
  5560.  
  5561. @ The output process uses a stack to keep track of what is going on at
  5562. different ``levels'' as the token lists are being written out. Entries on
  5563. this stack have three parts:
  5564.  
  5565. \yskip\hang |end_field| is the |tok_mem| location where the token list of a
  5566. particular level will end;
  5567.  
  5568. \yskip\hang |tok_field| is the |tok_mem| location from which the next token
  5569. on a particular level will be read;
  5570.  
  5571. \yskip\hang |mode_field| is the current mode, either |inner| or |outer|.
  5572.  
  5573. \yskip\noindent The current values of these quantities are referred to
  5574. quite frequently, so they are stored in a separate place instead of in the
  5575. |stack| array. We call the current values |cur_end|, |cur_tok|, and
  5576. |cur_mode|.
  5577.  
  5578. The global variable |stck_ptr| tells how many levels of output are
  5579. currently in progress. The end of output occurs when an |end_translation|
  5580. token is found, so the stack is never empty except when we first begin the
  5581. output process.
  5582.  
  5583. @d inner 0 /* Value of |mode| for \cee\ texts within \TeX\ texts */
  5584. @d outer 1 /* Value of |mode| for \cee\ texts in modules */
  5585.  
  5586. @<Typed...@>=
  5587.  
  5588. typedef int mode;
  5589.  
  5590. typedef struct {
  5591.   token_pointer end_field; /* Ending location of token list */
  5592.   token_pointer tok_field; /* Present location within token list */
  5593.   boolean mode_field; /* Interpretation of control tokens */
  5594. } output_state;
  5595.  
  5596. typedef output_state HUGE *stack_pointer;
  5597.  
  5598. @d cur_end cur_state.end_field /* Current ending location in |tok_mem| */
  5599. @d cur_tok cur_state.tok_field /* Location of next output token in |tok_mem| */
  5600. @d cur_mode cur_state.mode_field /* Current mode of interpretation */
  5601. @d ini_stack stck_ptr=stack;cur_mode=outer /* Initialize the stack */
  5602.  
  5603. @<Global...@>=
  5604.  
  5605. EXTERN output_state cur_state; /* |cur_end|, |cur_tok|, |cur_mode| */
  5606.  
  5607. EXTERN BUF_SIZE stck_size;
  5608. EXTERN output_state HUGE *stack; /* Dynamic array of info for non-current
  5609.                     levels */ 
  5610. EXTERN stack_pointer stck_end; /* End of |stack| */
  5611.  
  5612. EXTERN stack_pointer stck_ptr; /* First unused location in the output
  5613.                 state stack */ 
  5614. EXTERN stack_pointer mx_stck_ptr; /* Largest value assumed by |stck_ptr| */
  5615.  
  5616. @
  5617. @<Alloc...@>=
  5618.  
  5619. ALLOC(output_state,stack,ABBREV(stck_size_w),stck_size,0);
  5620. stck_end=stack+stck_size-1; /* End of |stack| */
  5621.  
  5622. @<Set init...@>=
  5623.  
  5624. mx_stck_ptr=stack;
  5625.  
  5626. @ To insert token-list |p| into the output, the |push_level| subroutine is
  5627. called; it saves the old level of output and gets a new one going.  The
  5628. value of |cur_mode| is not changed.
  5629.  
  5630. @<Part 2@>=@[
  5631.  
  5632. SRTN push_level FCN((p)) /* Suspends the current level */
  5633.     text_pointer p C1("")@;
  5634. {
  5635.   if (stck_ptr==stck_end) OVERFLW("stack levels",ABBREV(stck_size_w));
  5636.  
  5637.   if (stck_ptr>stack) { /* save current state */
  5638.     stck_ptr->end_field=cur_end;
  5639.     stck_ptr->tok_field=cur_tok;
  5640.     stck_ptr->mode_field=cur_mode;
  5641.   }
  5642.  
  5643.   stck_ptr++;
  5644.  
  5645.   if (stck_ptr>mx_stck_ptr) mx_stck_ptr=stck_ptr;
  5646.  
  5647.   cur_tok=*p; cur_end=*(p+1);
  5648. }
  5649.  
  5650. @ Conversely, the |pop_level| routine restores the conditions that were in
  5651. force when the current level was begun. This subroutine will never be
  5652. called when |stck_ptr=1|.
  5653.  
  5654. @<Part 2@>=@[
  5655.  
  5656. SRTN pop_level(VOID)
  5657. {
  5658.   cur_end=(--stck_ptr)->end_field;
  5659.   cur_tok=stck_ptr->tok_field; cur_mode=stck_ptr->mode_field;
  5660. }
  5661.  
  5662. @ The |get_output| function returns the next byte of output that is not a
  5663. reference to a token list. It returns the values |identifier| or |res_word|
  5664. or |mod_name| if the next token is to be an identifier (typeset in
  5665. italics), a reserved word (typeset in boldface) or a module name (typeset
  5666. by a complex routine that might generate additional levels of output).  In
  5667. these cases |cur_name| points to the identifier or module name in question.
  5668.  
  5669. @<Global...@>=
  5670.  
  5671. EXTERN name_pointer cur_name;
  5672.  
  5673. @d res_word OCTAL(201) /* Returned by |get_output| for reserved words */
  5674. @d mod_name OCTAL(200) /* Returned by |get_output| for module names */
  5675.  
  5676. @<Part 2@>=@[
  5677.  eight_bits get_output(VOID) /* Returns the next token of output */
  5678. {
  5679.   sixteen_bits a; /* Current item read from |tok_mem| */
  5680.  
  5681.   restart: while (cur_tok==cur_end) pop_level(); /* Get back to unfinished
  5682.         level. */
  5683.  
  5684.   a=*(cur_tok++);
  5685.  
  5686.   if (a>=0400) 
  5687.     {
  5688.     cur_name=a % id_flag + name_dir;
  5689.  
  5690.     switch (a / id_flag) 
  5691.         {
  5692.       case 2: return res_word; /* |a==res_flag+cur_name| */
  5693.       case 3: return mod_name; /* |a==mod_flag+cur_name| */
  5694.       case 4: push_level(a % id_flag + tok_start); goto restart;
  5695.     /* |a==tok_flag+cur_name| */
  5696.       case 5: push_level(a % id_flag + tok_start); cur_mode=inner; 
  5697.         goto restart; 
  5698.       /* |a==inner_tok_flag+cur_name| */
  5699.       default: return identifier; /* |a==id_flag+cur_name| */
  5700.         }
  5701.       }
  5702.  
  5703. /* If we get here, it's a single-byte token. */
  5704. return (eight_bits)a;
  5705. }
  5706.  
  5707. @ The real work associated with token output is done by |make_output|.
  5708. This procedure appends an |end_translation| token to the current token
  5709. list, and then it repeatedly calls |get_output| and feeds characters to the
  5710. output buffer until reaching the |end_translation| sentinel. It is possible
  5711. for |make_output| to be called recursively, since a module name may include
  5712. embedded \cee\ text; however, the depth of recursion never exceeds one
  5713. level, since module names cannot be inside of module names.
  5714.  
  5715. A procedure called |output_C| does the scanning, translation, and output of
  5716. \cee\ text within `\Cb'~brackets, and this procedure uses |make_output| to
  5717. output the current token list. Thus, the recursive call of |make_output|
  5718. actually occurs when |make_output| calls |output_C| while outputting the
  5719. name of a module.
  5720. @^recursion@>
  5721.  
  5722. @<Part 2@>=@[
  5723.  
  5724. SRTN output_C(VOID) /* Outputs the current token list */
  5725. {
  5726.   token_pointer save_tok_ptr;
  5727.   text_pointer save_text_ptr;
  5728.   eight_bits save_next_control; /* Values to be restored */
  5729.   text_pointer p; /* Translation of the \cee\ text */
  5730.  
  5731.   save_tok_ptr=tok_ptr; save_text_ptr=text_ptr;
  5732.   save_next_control=next_control;
  5733.  
  5734.   next_control=ignore; p=C_translate();
  5735.   APP_FLAG(inner_tok,p,tok_start);
  5736.  
  5737.   make_output(); /* output the list */
  5738.  
  5739.   if (text_ptr>mx_text_ptr) mx_text_ptr=text_ptr;
  5740.   if (tok_ptr>mx_tok_ptr) mx_tok_ptr=tok_ptr;
  5741.  
  5742.   text_ptr=save_text_ptr; tok_ptr=save_tok_ptr; /* Forget the tokens */
  5743.   next_control=save_next_control; /* Restore |next_control| to original
  5744.         state */ 
  5745. }
  5746.  
  5747. @ Here is \.{WEAVE}'s major output handler.
  5748.  
  5749. @<Part 3@>=@[
  5750.  
  5751. SRTN make_output(VOID) /* outputs the equivalents of tokens */
  5752. {
  5753.   eight_bits a; // Current output byte.
  5754.   eight_bits b; // Next output byte.
  5755.   int c; // Count of |indent| and |outdent| tokens.
  5756.   boolean copying = NO; // Are we copying the \TeX\ part of a comment?
  5757.  
  5758.   app(end_translation); // Append a sentinel.
  5759.   freeze_text; push_level(text_ptr-1);
  5760.  
  5761. WHILE()
  5762.     {
  5763.     a = get_output();
  5764.  
  5765. reswitch: switch(a) 
  5766.         {
  5767.     case ignore: continue; // In case a null sneaks in.
  5768.  
  5769.     case begin_language:
  5770.         language = lan_enum(get_output()); /* The byte after
  5771. |begin_language| contains the language number. */
  5772.         continue;
  5773.  
  5774.     @<Cases for turning output on or off@>@:@;
  5775.       case end_translation: 
  5776.     return;
  5777.  
  5778.       case identifier: case res_word: 
  5779.     if(output_on) 
  5780.         @<Output an identifier@>@; 
  5781.     break;
  5782.  
  5783.       case mod_name: 
  5784.     if(output_on) 
  5785.         @<Output a module name@>@; @+ break;
  5786.  
  5787.       case math_bin: case math_rel: 
  5788.         @<Output a \.{\\math} operator@>; @+ break;
  5789.  
  5790.       case cancel: 
  5791.         c=0; while ((a=get_output())>=indent && a<=big_force) 
  5792.             {
  5793.               if (a==indent) c++; if (a==outdent) c--;
  5794.                 }
  5795.             @<Output saved |indent| or |outdent| tokens@>;
  5796.             goto reswitch;
  5797.  
  5798.       case big_cancel: 
  5799.     c=0;
  5800.     while (((a=get_output())>=indent || a==@' ') && a<=big_force) 
  5801.             {
  5802.               if (a==indent) c++; if (a==outdent) c--;
  5803.                 }
  5804.         @<Output saved...@>;
  5805.         goto reswitch;
  5806.  
  5807.       case indent: case outdent: case opt: case backup: case break_space:
  5808.       case force: case big_force: 
  5809.     @<Output a control,
  5810.         look ahead in case of line breaks, possibly |goto reswitch|@>; break;
  5811.  
  5812.       case interior_semi:
  5813.         if(output_on) out(';');
  5814.         break;
  5815.  
  5816.       case @'*': 
  5817.     if(!(copying || nuweb_mode))
  5818.         {
  5819.         OUT_STR("\\ast "); // Special macro for asterisks in code mode.
  5820. @.\\ast@>
  5821.         break; 
  5822.         }
  5823. /* If |copying|, the asterisk case falls through to the default. */
  5824.  
  5825.       default: 
  5826.     if(output_on) 
  5827.         out(a); // Otherwise |a| is an |ASCII| character.
  5828.     }
  5829.   }
  5830. }
  5831.  
  5832. @
  5833. @<Cases for turning output on...@>=
  5834.  
  5835. case copy_mode:
  5836.     copying = BOOLEAN(!copying); @+ break;
  5837.  
  5838. case turn_output_off:
  5839. @%        OUT_STR("OFF"); // For debugging.
  5840.     output_on = NO;
  5841.     break;
  5842.  
  5843. case turn_output_on:
  5844. @%        OUT_STR("ON"); // For debugging.
  5845.     output_on = YES;
  5846.     break;
  5847.  
  5848. case Turn_output_off:
  5849.     skip_file();
  5850.     strt_off = YES;
  5851.     output_on = NO;
  5852.     break;
  5853.  
  5854. case Turn_output_on:
  5855.     strt_off = NO;
  5856.     output_on = YES;
  5857.     break;
  5858.  
  5859.  
  5860. @
  5861. @<Part 3@>=@[
  5862. SRTN skip_file(VOID)
  5863. {
  5864. #define TEMP_LEN (MAX_FILE_NAME_LENGTH + 11)
  5865.  
  5866. outer_char temp[TEMP_LEN],temp1[TEMP_LEN];
  5867.  
  5868. esc_file_name(temp1,TEMP_LEN,prms[1].web.File_name);
  5869. SPRINTF(TEMP_LEN,temp,`"\\Wskipped{%s}",temp1`);
  5870. OUT_STR(temp);
  5871. fin_line();
  5872.  
  5873. #undef TEMP_LEN
  5874. }
  5875.  
  5876. @
  5877. @<Part 3@>=@[
  5878. SRTN out_skip(VOID)
  5879. {
  5880. @<Toggle output@>;
  5881. if(!output_on) 
  5882.     {
  5883.     output_on = YES;
  5884.     OUT_STR("\\WY\\WP");
  5885.     skip_file();
  5886.     output_on = NO;
  5887.     }
  5888. }
  5889.  
  5890.  
  5891. @<Output an identifier@>=
  5892. {
  5893. if(nuweb_mode)
  5894.     {
  5895.     ASCII HUGE *k;
  5896.  
  5897.     for(k=cur_name->byte_start; k<(cur_name+1)->byte_start; k++)
  5898.         {
  5899.         out(*k);
  5900.         }
  5901.     }
  5902. else
  5903.     @<Format and output an identifier@>@;
  5904. }
  5905.  
  5906.  
  5907. @ An identifier of length one does not have to be enclosed in braces, and
  5908. it looks slightly better if set in a math-italic font instead of a
  5909. (slightly narrower) text-italic font. Thus we output `\.{\\\char'174a}' but
  5910. `\.{\\]\{aa\}}'.
  5911.  
  5912. @<Format and output an id...@>=
  5913. {
  5914. if (a==identifier)
  5915.   {
  5916.   if(is_intrinsic(cur_name)) 
  5917.     OUT_STR(pfmt->intrinsic); 
  5918.     /* Intrinsic function---e.g., |fopen|.  */
  5919. @.\\\AT!@>
  5920.   else if(is_keyword(cur_name)) 
  5921.     OUT_STR(pfmt->keyword); 
  5922.     /* Fortran keyword---e.g., |@r BLOCKSIZE|.  */
  5923. @.\\.@>
  5924.   else if (length(cur_name)==1) 
  5925.     OUT_STR(pfmt->short_id); 
  5926.     /* One-character identifier---e.g., |a|. */
  5927. @.\\|@>
  5928.   else 
  5929.     @<Output the appropriate identifier prefix@>@;
  5930.   }
  5931. else 
  5932.     OUT_STR(pfmt->reserved); /* Reserved word---e.g., |float|. */
  5933. @.\\\&@>
  5934.  
  5935. out_name(IDENTIFIER,cur_name);
  5936. }
  5937.  
  5938. @ Some people prefer macros to be formatted differently from ordinary
  5939. identifiers.
  5940. @<Output the appro...@>=
  5941. switch(DEFINED_TYPE(cur_name))
  5942.     {
  5943.     case D_MACRO:
  5944.     OUT_STR(pfmt->id_outer); // E.g., |NON_TEX_MACRO|.
  5945.     break;
  5946.  
  5947.     case M_MACRO:
  5948.     OUT_STR(pfmt->id_inner); // E.g., |_FWEAVE_|.
  5949.     break;
  5950.  
  5951.     default:
  5952.     OUT_STR(pfmt->id); // Longer ordinary identifier---e.g., |out|.
  5953.     break;
  5954. @.\\\\@>
  5955.     }
  5956.  
  5957. @ Here |a|~will only be |math_bin| or |math_rel|.
  5958. @<Output a \....@>=
  5959.  
  5960. OUT_STR(a==math_bin ? "\\mathbin{" : "\\mathrel{");
  5961. @.\\mathbin@>
  5962. @.\\mathrel@>
  5963.  
  5964. @ The current mode does not affect the behavior of \.{WEAVE}'s output routine
  5965. except when we are outputting control tokens.
  5966.  
  5967. @<Output a control...@>=
  5968.  
  5969. if (a<break_space) 
  5970.     {
  5971.       if (cur_mode==outer) 
  5972.         {
  5973.         if(output_on)
  5974.             {
  5975.             out(@'\\'); @+ out(a-cancel+@'0'); /* As an example,
  5976. $|backup| = |0345| - |0341| + \.{'0'} = \.{'4'} \to \.{\\4}$. */
  5977.             }
  5978.         if (a==opt) 
  5979.         if(output_on) {out(get_output());} /* |opt| is followed by a
  5980. digit. */ 
  5981.         else get_output();
  5982.          }
  5983.       else if (a==opt) b=get_output(); // Ignore digit following |opt|.
  5984.       }
  5985. else @<Look ahead for strongest line break, |goto reswitch|@>; /* Here $a
  5986.     \in \{|break_space|,|force|,|big_force|\}$. */
  5987.  
  5988. @ If several of the tokens |break_space|, |force|, |big_force| occur in a
  5989. row, possibly mixed with blank spaces (which are ignored), the largest one
  5990. is used. A line break also occurs in the output file, except at the very
  5991. end of the translation. The very first line break is suppressed (i.e., a
  5992. line break that follows `\.{\\WY\\WP}').
  5993.  
  5994. @<Look ahead for st...@>= 
  5995. {
  5996. boolean save_mode; /* value of |cur_mode| before a sequence of breaks */
  5997.  
  5998.   b=a; save_mode=cur_mode; c=0;
  5999.  
  6000. WHILE()
  6001.     {
  6002.         a = get_output();
  6003.  
  6004.         if (a==cancel || a==big_cancel) 
  6005.         {
  6006.           @<Output saved |indent| or |outdent| tokens@>;
  6007.           goto reswitch; // |cancel| overrides everything.
  6008.             }
  6009.  
  6010.         if ((a!=@' ' && a<indent) || a==backup || a>big_force) 
  6011.         { // Time to output something.
  6012.           if (save_mode==outer) 
  6013.             {
  6014.             if (out_ptr>out_buf+5 && 
  6015.                 STRNCMP(out_ptr-5,"\\WY\\WP",6)==0)
  6016.                   goto reswitch;
  6017.                 @<Output saved |indent| or |outdent| tokens@>;
  6018.             if(output_on)
  6019.                if(strt_off)
  6020.                 {
  6021.                 if(STRNCMP(out_ptr-2,"\\WP",3)==0)
  6022.                       {
  6023.                       out_ptr = out_buf;
  6024.                       goto reswitch;
  6025.                       }
  6026.                 }
  6027.                else
  6028.                 {
  6029.                     out(@'\\'); @+ out(b-cancel+@'0');
  6030.                 }
  6031.                 if (a!=end_translation) fin_line();
  6032.               }
  6033.           else if (a!=end_translation && cur_mode==inner) 
  6034.         if(output_on) out(@' ');
  6035.  
  6036.           goto reswitch;
  6037.         }
  6038.  
  6039.         if (a==indent) c++;
  6040.         else if (a==outdent) c--;
  6041.         else 
  6042. /* Use only the largest. */
  6043.         if (a>b) b=a; /* if |a==' '| we have |a<b| */
  6044.         else if(a==opt) get_output(); /* Throw away digit after
  6045.                             |opt|. */ 
  6046.       }
  6047. }
  6048.  
  6049. @  While we're removing unwanted or duplicate tokens, we don't want to lose
  6050. track of the indent level.  So we count the |indent|s and |outdent|s, and
  6051. write out the net here.
  6052.  
  6053. @<Output saved...@>=
  6054.  
  6055.   for (;c>0;c--) OUT_STR("\\1");
  6056.  
  6057.   for (;c<0;c++) OUT_STR("\\2");
  6058.  
  6059. @ The remaining part of |make_output| is somewhat more complicated. When we
  6060. output a module name, we may need to enter the parsing and translation
  6061. routines, since the name may contain code embedded in \Cb\~constructions.
  6062. This code is placed at the end of the active input buffer and the
  6063. translation process uses the end of the active |tok_mem| area.
  6064.  
  6065. @<Output a module name@>= 
  6066. #if FCN_CALLS
  6067.     out_md_name();
  6068. #else
  6069.     @<Code to output a module name@>@;
  6070. #endif
  6071.  
  6072. @
  6073. @<Part 3@>=
  6074.  
  6075. #if FCN_CALLS
  6076. @[SRTN out_md_name(VOID)
  6077. {
  6078. @<Code to output a module name@>@;
  6079. }
  6080. #endif
  6081.  
  6082. @
  6083. @<Code to output a module name@>=
  6084. {
  6085. name_pointer cur_mod_name; /* name of module being output */
  6086.  
  6087.   OUT_STR("\\WX");
  6088. @.\\WX@>
  6089.   cur_xref = (xref_pointer)cur_name->xref;
  6090.  
  6091.  /* Output the module number, or zero if it was undefined */
  6092.   if (cur_xref->num>=def_flag) 
  6093.     {
  6094.         out_mod(cur_xref->num-def_flag,ENCAP);
  6095.  
  6096.         if (phase==3) 
  6097.         {
  6098.           cur_xref=cur_xref->xlink;
  6099.  
  6100.           while (cur_xref->num>=def_flag) 
  6101.             {
  6102.             OUT_STR(", ");
  6103.                 out_mod(cur_xref->num-def_flag,ENCAP);
  6104.              cur_xref=cur_xref->xlink;
  6105.               }
  6106.          }
  6107.     }
  6108.   else out(@'0');
  6109.  
  6110.     out(@':');  /* End the module number. */
  6111.     @<Output the text of the module name@>;
  6112.     OUT_STR("\\X ");  /* End the text. (Can't use a colon here, because
  6113. there may be colons in the text.) */
  6114.     OUT_STR(cur_xref->num >= def_flag ? 
  6115.     language_symbol((LANGUAGE)cur_mod_name->mod_info->language) :
  6116.         (CONST outer_char *)"");
  6117.     OUT_STR("\\X"); /* End the language marker. */
  6118. }
  6119.  
  6120. @ In most situations, we only want to output a language marker if we're in
  6121. a language different from the global language.
  6122.  
  6123. @d language_name_ptr(l) languages[lan_num(l)] /* Points to the full
  6124.                     language name. */
  6125. @d language_symbol(l) 
  6126.     (l!=global_language ? LANGUAGE_CODE(l) : (CONST outer_char *)"")
  6127.  
  6128. @<Output the text...@>=
  6129. {
  6130. ASCII HUGE *k,  HUGE *k_limit; /* indices into |byte_mem| */
  6131. ASCII HUGE *j; /* index into |cur_buffer| */
  6132. ASCII HUGE *save_loc, HUGE *save_limit; // |loc| and |limit| to be restored.
  6133. eight_bits b;
  6134.  
  6135. k=cur_name->byte_start; k_limit=(cur_name+1)->byte_start;
  6136. cur_mod_name=cur_name;
  6137.  
  6138. while (k<k_limit) 
  6139.     {
  6140.       b=*(k++);
  6141.  
  6142.       if (b==@'@@') @<Skip next character, give error if not `\.{@@}'@>;
  6143.  
  6144.       if (b!=@'|') out(b)@;
  6145.       else 
  6146.         {
  6147.         @<Copy the \cee\ text into the |cur_buffer| array@>;
  6148.         save_loc=loc; save_limit=limit; loc=limit+2; limit=j+1;
  6149.         *limit=@'|'; output_C();
  6150.         loc=save_loc; limit=save_limit;
  6151.           }
  6152.     }
  6153. }
  6154.  
  6155. @<Skip next char...@>=
  6156.  
  6157. if (*k++!=@'@@') 
  6158. {
  6159. SET_COLOR(error);
  6160.   printf("\n! Illegal control code in section name: <");
  6161. @.Illegal control code...@>
  6162.   prn_id(cur_mod_name); printf("> "); mark_error;
  6163. }
  6164.  
  6165. @ The \cee\ text enclosed in~\Cb\ should not contain `\vertbar'~characters,
  6166. except within strings. We put a~`\vertbar' at the front of the buffer, so
  6167. that an error message that displays the whole buffer will look a little bit
  6168. sensible.  The variable |delim| is zero outside of strings, otherwise it
  6169. equals the delimiter that began the string being copied.
  6170.  
  6171. @<Copy the \cee\ text into...@>=
  6172. {
  6173. ASCII delim; /* first and last character of string being copied */
  6174.  
  6175. j=limit+1; *j=@'|'; delim=0;
  6176.  
  6177. WHILE()
  6178.     {
  6179.       if (k>=k_limit) 
  6180.         {
  6181.         SET_COLOR(error);
  6182.             printf("\n! C text in section name didn't end: <");
  6183. @.C text...didn't end@>
  6184.             prn_id(cur_mod_name); printf("> "); mark_error; break;
  6185.           }
  6186.  
  6187.       b=*(k++);
  6188.  
  6189.       if (b==@'@@') @<Copy a control code into the buffer@>@;
  6190.       else 
  6191.         {
  6192.             if (b==@'\'' || b==@'"')
  6193.               if (delim==0) delim=b;
  6194.               else if ((eight_bits)delim == b) delim=0;
  6195.  
  6196.             if (b!=@'|' || delim!=0) 
  6197.             {
  6198.               if (j>cur_buffer+buf_size-2) OVERFLW("buffer","");
  6199.  
  6200.               *(++j)=b;
  6201.                 }
  6202.             else break;
  6203.           }
  6204.     }
  6205. }
  6206.  
  6207. @<Copy a control code into the buffer@>= 
  6208. {
  6209.   if (j>cur_buffer+buf_size-3) OVERFLW("buffer","");
  6210.  
  6211.   *(++j)=@'@@'; *(++j)=*(k++);
  6212. }
  6213.  
  6214. @* PHASE TWO PROCESSING.  We have assembled enough pieces of the puzzle in
  6215. order to be ready to specify the processing in \.{WEAVE}'s main pass over
  6216. the source file. Phase two is analogous to phase one, except that more work
  6217. is involved because we must actually output the \TeX\ material instead of
  6218. merely looking at the \.{WEB} specifications.
  6219.  
  6220. @<Part 2@>=@[
  6221.  
  6222. SRTN phase2(VOID) 
  6223. {
  6224. extern outer_char wbflnm0[];
  6225.  
  6226. phase = 2; // Prepare for second phase.
  6227. the_part = LIMBO;
  6228.  
  6229. params = global_params;
  6230. frz_params();
  6231.  
  6232. rst_input(); 
  6233. strt_off = ending_off = NO;
  6234. writing(YES,tex_fname); @+ if(tex_file==stdout) putchar('\n');
  6235.  
  6236. fin_line(); // Write out the ``\.{\\input\ fwebmac.sty}''.
  6237.  
  6238. @<Issue the \.{\\Wbegin} command that sets up the beginning of the document@>@;
  6239.  
  6240. module_count=0; 
  6241.  
  6242. copy_limbo();
  6243. flush_buffer(out_buf,NO); /* Insert a blank line, it looks nice */ 
  6244.  
  6245. math_flag=NO;
  6246. while (!input_has_ended) 
  6247.     @<Translate the current module@>;
  6248. }
  6249.  
  6250. @ After the macros have been read in, we are ready to
  6251. actually begin the document.  The command has the form
  6252. ``\.{\\Wbegin[\It{options}]\{\It{style}\}\{\It{TeXindent}\}\{\It{codeindent}\}
  6253. \{\It{contents}\}
  6254. \{\{\It{reserved}\}\{\It{short identifier}\}\{\It{identifier}\}
  6255. \{\It{outer macro}\}\{\It{inner macro}\}
  6256. \{\It{intrinsic}\}\{\It{keyword}\}\{\It{typewriter}\}\{\It{modtrans}\}\}}.''  
  6257. The \It{options} and \It{style} field are used only by \LaTeX.
  6258. @<Issue the \.{\\Wbegin} command...@>=
  6259. {
  6260. #define TEMP_LEN (MAX_FILE_NAME_LENGTH + 100)
  6261. #define ARGS w_style.misc.LaTeX.options,w_style.misc.LaTeX.style,\
  6262.     w_style.misc.TeXindent,w_style.misc.codeindent,\
  6263.     w_style.contents.tex,\
  6264.     pfmt->reserved,\
  6265.         pfmt->short_id,pfmt->id,\
  6266.         pfmt->id_outer,pfmt->id_inner,\
  6267.         pfmt->intrinsic,pfmt->keyword,\
  6268.         pfmt->typewritr,\
  6269.     w_style.indx.encap_prefix
  6270.  
  6271. outer_char temp0[TEMP_LEN];
  6272. outer_char HUGE *temp1 = GET_MEM("temp1",TEMP_LEN,outer_char);
  6273.  
  6274. SPRINTF(TEMP_LEN,temp0,
  6275.        `"\n\\Wbegin[%s]{%s}{%s}{%s}{%s}{{%s}{%s}{%s}{%s}{%s}{%s}{%s}{%s}}{%s}",
  6276.     ARGS`);
  6277. OUT_STR(xpn_name(&temp1,TEMP_LEN,temp0,wbflnm0));
  6278. FREE(temp1);
  6279. fin_line();
  6280.  
  6281. #undef TEMP_LEN
  6282. #undef ARGS
  6283. }
  6284.  
  6285. @ The output file will contain the control sequence~\.{\\WY} between
  6286. non-null sections of a module, e.g., between the \TeX\ and definition parts
  6287. if both are nonempty. This puts a little white space between the parts when
  6288. they are printed. However, we don't want \.{\\WY} to occur between two
  6289. definitions within a single module. The variables |out_line| or |out_ptr|
  6290. will change if a section is non-null, so the following macros
  6291. `|save_position|' and `|emit_space_if_needed|' are able to handle the
  6292. situation:
  6293.  
  6294. @d save_position save_line=out_line; save_place=out_ptr
  6295. @d emit_space_if_needed if (save_line!=out_line || save_place!=out_ptr)
  6296.   {
  6297.   OUT_STR("\\WY");
  6298. @.\\WY@>
  6299.   yskipped = YES;
  6300.   }
  6301.  
  6302. @<Global...@>=
  6303.  
  6304. EXTERN LINE_NUMBER save_line; // Former value of |out_line|.
  6305. EXTERN ASCII HUGE *save_place; // Former value of |out_ptr|.
  6306. EXTERN boolean in_module SET(NO); // Between \.{\\WN} and \.{\\fi}?
  6307. EXTERN boolean yskipped SET(NO); // Did we skip between parts?
  6308.  
  6309. @<Translate the current module@>= 
  6310. {
  6311. the_part = TEX_;
  6312.  
  6313. /* Again, all modules start off in the global language. */
  6314. params = global_params;
  6315. frz_params();
  6316.  
  6317.   module_count++;
  6318.  
  6319.   @<Output the code for the beginning of a new module@>;
  6320.   save_position;
  6321.  
  6322.   trns_TeX();
  6323.   trns_defn();
  6324.   trns_code();
  6325.  
  6326.   @<Show cross-references to this module@>;
  6327.   @<Output the code for the end of a module@>;
  6328. }
  6329.  
  6330. @ Modules beginning with the \.{WEB} control sequence~`\.{@@\ }' start in the
  6331. output with the \TeX\ control sequence~`\.{\\WM}', followed by the module
  6332. number. Similarly, `\.{@@*}'~modules lead to the control sequence~`\.{\\WN}'.
  6333. If this is a changed module, we put~\.{*} just before the module number.
  6334.  
  6335. @<Output the code for the beginning...@>=
  6336. {
  6337. @<Output the include file name if necessary@>;
  6338.  
  6339. if(!in_module && output_on)
  6340.     {
  6341.     OUT_STR(*(loc-1) == @'*' ? "\\WN" : "\\WM");
  6342. @.\\WM@>
  6343. @.\\WN@>
  6344.     in_module = YES;
  6345.  
  6346.     out_mod(module_count,NO_ENCAP); OUT_STR(". ");
  6347.     }
  6348.  
  6349. progress(); // Progress report to terminal.
  6350. }
  6351.  
  6352. @ These variables remember the last and current name of the include file.
  6353. @<Glob...@>=
  6354.  
  6355. IN_COMMON outer_char last_include_file[],this_include_file[];
  6356.  
  6357. @<Output the include file name...@>=
  6358.  
  6359. if(STRCMP(last_include_file,this_include_file) != 0)
  6360.     {
  6361.     STRCPY(last_include_file,this_include_file);
  6362.     OUT_STR("\\WIF{"); @+ out_fname(this_include_file); @+
  6363.         OUT_STR("}"); 
  6364.     fin_line();
  6365.     }
  6366.  
  6367. @ In the \TeX\ part of a module, we simply copy the source text, except that
  6368. index entries are not copied and \cee\ text within \Cb\ is translated.
  6369.  
  6370. @<Part 2@>=@[
  6371.  
  6372. SRTN trns_TeX(VOID)
  6373. {
  6374. the_part = TEX_;
  6375. parsing_mode = OUTER;
  6376.  
  6377. do
  6378.     {
  6379.     next_control = copy_TeX();
  6380.  
  6381.     switch(next_control) 
  6382.         {
  6383.        @<Cases to set |language| and |break|@>@:@;
  6384.  
  6385.        case toggle_output: 
  6386.         out_skip();
  6387.         break;
  6388.  
  6389.         case @'|': ini_stack; output_C(); break;
  6390.  
  6391.         case math_break: 
  6392.         out(@'|'); // Literal vertical bar.
  6393.         break;
  6394.  
  6395.         case @'@@': 
  6396.         out(@'@@'); // Literal '\.{@@}'.
  6397.         break;
  6398.  
  6399.        case invisible_cmnt:  loc = limit + 1; break;
  6400.  
  6401.        case begin_meta:
  6402.         OUT_STR(w_style.misc.meta.TeX.begin); 
  6403.         break;
  6404.  
  6405.        case end_meta:
  6406.         OUT_STR(w_style.misc.meta.TeX.end); 
  6407.         break;
  6408.  
  6409.         case TeX_string: 
  6410.             case xref_roman: case xref_wildcard: case xref_typewriter:
  6411.         case macro_module_name: case module_name: 
  6412.         loc-=2; next_control=get_next(); /* skip to \.{@@>} */ 
  6413.  
  6414.       if (next_control==TeX_string)
  6415.         ERR_PRINT(W,"TeX string should be in code text only"); break;
  6416. @.TeX string should be...@>
  6417.  
  6418.     case thin_space: 
  6419.     case line_break: case big_line_break: case no_line_break: case join:
  6420.     case pseudo_semi: case pseudo_expr: case pseudo_colon:
  6421.     case compiler_directive: case Compiler_Directive:
  6422.     case no_index:
  6423.     case begin_bp: case insert_bp:
  6424.      ERR_PRINT(W,"You can't do that in TeX text"); break;
  6425. @.You can't do that...@>
  6426.         }
  6427.     } 
  6428. while (next_control<formatt);
  6429. }
  6430.  
  6431. @ We need a flag to suppress phase~2 declarations of stuff recognized
  6432. during macro definitions.
  6433. @<Glob...@>=
  6434.  
  6435. EXTERN boolean ok_to_define SET(YES);
  6436. EXTERN boolean q_protected SET(NO); // For protecting with quotes.
  6437. EXTERN boolean suppress_defn SET(NO); // For masking out formats, etc.
  6438.  
  6439. @ When we get to the following code we have |next_control>=formatt|, and
  6440. the token memory is in its initial empty state.
  6441.  
  6442. @d SUPPRESS(name) if(!defn_mask.name) suppress_defn = YES
  6443.  
  6444. @<Part 2@>=@[
  6445.  
  6446. SRTN trns_defn(VOID)
  6447. {
  6448. boolean overload_ops0 = overload_ops;
  6449.  
  6450. the_part = DEFINITION;
  6451. parsing_mode = OUTER;
  6452.  
  6453. if (next_control<begin_code) 
  6454.     { /* definition part non-empty */
  6455.     emit_space_if_needed; save_position;
  6456.     @<Store the output switch@>@;
  6457. @%    @<Append \.{\\WP}@>@;
  6458.     }
  6459.  
  6460. while (next_control<begin_code) 
  6461.     @<Translate a |definition|, |formatt|, etc.@>@;
  6462. }
  6463.  
  6464. @ Now deal with a |formatt|, |definition|, |undefinition|, |WEB_definition|,
  6465. |limbo_text|, |op_def|, |macro_def|,  or \.{@@\#...} command.
  6466.  
  6467. @<Translate a |definition|...@>=
  6468. {
  6469. eight_bits last_control = next_control;
  6470. boolean nuweb_mode0;
  6471.  
  6472. ini_stack;
  6473.  
  6474. switch(next_control)
  6475.     {
  6476.    case begin_comment:
  6477.    case invisible_cmnt:
  6478.     break;
  6479.  
  6480.    default:
  6481.     @<Store the output switch@>@;
  6482.     break;
  6483.     }
  6484.  
  6485. nuweb_mode0 = nuweb_mode;
  6486. nuweb_mode = NO;
  6487.  
  6488. switch(next_control)
  6489.     {
  6490.    case formatt:
  6491.     @<Start a format definition@>@;
  6492.     break;
  6493.  
  6494.    case limbo_text:
  6495.     @<Start a limbo text definition@>@;
  6496.     break;
  6497.  
  6498.    case op_def:
  6499.     @<Start an overloaded operator definition@>@;
  6500.     break;
  6501.  
  6502.    case macro_def:
  6503.     @<Start an overloaded identifier definition@>@;
  6504.     break;
  6505.  
  6506.    case begin_comment:
  6507.     doing_cdir = NO;
  6508.     break;
  6509.  
  6510.    case invisible_cmnt:
  6511.     loc = limit + 1; // Skip the line.
  6512. /* Skip any other extraneous material that doesn't belong in the definition
  6513. section. */ 
  6514.     while((next_control=get_next()) < formatt
  6515.         && next_control!=begin_comment);
  6516.     continue;
  6517.  
  6518.    default:
  6519.     @<Start a macro definition@>@;
  6520.     break;
  6521.     }
  6522.  
  6523. ok_to_define = NO;
  6524. nuweb_mode = nuweb_mode0;
  6525.  
  6526. outr_parse(); // Scan the definition or whatever.
  6527.  
  6528. if(auto_app_semi && last_control==WEB_definition) 
  6529.     {app_scrap(semi,maybe_math);}
  6530.  
  6531. overload_ops = overload_ops0;
  6532. fin_C(); // Finish up the definition or whatever.
  6533. ok_to_define = YES;
  6534. }
  6535.  
  6536. @ The switch into code mode is appended rather than just written directly
  6537. out in order to deal with the |output_on| status properly.
  6538. @<Append \.{\\WP}@>=
  6539. {
  6540. APP_STR("\\WP");
  6541. @.\\WP@>
  6542. }
  6543.  
  6544. @ The |fin_C| procedure outputs the translation of the current scraps,
  6545. preceded by the control sequence~`\.{\\WP}' and followed by the control
  6546. sequence~`\.{\\par}'. It also restores the token and scrap memories to
  6547. their initial empty state.
  6548.  
  6549. A |force| token is appended to the current scraps before translation takes
  6550. place, so that the translation will normally end with~\.{\\6} or~\.{\\7}
  6551. (the \TeX\ macros for |force| and |big_force|). This~\.{\\6} or~\.{\\7} is
  6552. replaced by the concluding \.{\\par} or by \.{\\WY\\par}.
  6553.  
  6554. @<Part 2@>=@[
  6555.  
  6556. SRTN fin_C(VOID) // Finishes a definition or a \cee\ part.
  6557. {
  6558. text_pointer p; // Translation of the scraps.
  6559. boolean current_output_state = output_on;
  6560.  
  6561. if(!suppress_defn)
  6562.     {
  6563. @%    output_on = YES;
  6564.     column_mode = NO;
  6565.  
  6566.     app_tok(force); // Last thing in the translation.
  6567.     app_scrap(ignore_scrap,no_math); 
  6568.         // The last stuff doesn't count for syntax.
  6569.  
  6570. /* We've accumulated all the stuff for one part.  Translate it, then print
  6571. it. */
  6572.     p = translate(OUTER);
  6573.  
  6574.     APP_FLAG(tok,p,tok_start);
  6575.     make_output(); // Output the list.
  6576.  
  6577.     if (out_ptr>out_buf+1)
  6578.         @<Tidy up the end of the part@>@;
  6579.  
  6580.     OUT_STR("\\par"); fin_line();
  6581.  
  6582. /* Accumulate statistics. */
  6583.     if (text_ptr>mx_text_ptr) 
  6584.         mx_text_ptr=text_ptr;
  6585.     if (tok_ptr>mx_tok_ptr) 
  6586.         mx_tok_ptr=tok_ptr;
  6587.     if (scrp_ptr>mx_scr_ptr) 
  6588.         mx_scr_ptr=scrp_ptr;
  6589.     }
  6590. else 
  6591.     suppress_defn = NO;
  6592.  
  6593. /* Forget the tokens and the scraps. */  
  6594. tok_ptr=tok_mem+1; text_ptr=tok_start+1; scrp_ptr=scrp_info;
  6595.  
  6596. #if(0)
  6597. if(strt_off) output_on = strt_off = ending_off = NO;
  6598. if(ending_off)
  6599.     {
  6600.     strt_off = ending_off = NO;
  6601.     output_on = YES;
  6602.     }
  6603. #endif
  6604.  
  6605. output_on = current_output_state;
  6606. }
  6607.  
  6608. @
  6609. @<Tidy up...@>=
  6610. {
  6611.         if (*(out_ptr-1)==@'\\')
  6612.             {
  6613. @.\\6@>
  6614. @.\\7@>
  6615. @.\\WY@>
  6616.             if (*out_ptr==@'6') 
  6617.                 out_ptr -= 2; // Throw away the \.{\\6}.
  6618.             else if (*out_ptr==@'7') 
  6619.                 {
  6620.                 out_ptr -= 2; // Throw away the \.{\\7}\dots
  6621.                 OUT_STR("\\WY"); 
  6622.                     // and replace it with \.{\\WY}.
  6623.                 }
  6624.             }
  6625. }
  6626.  
  6627. @ Here is a nucleus that writes out the appropriate macro for the
  6628. preprocessor command.
  6629.  
  6630. @d APP_TEMP(letter,arg) app_temp(OC(letter),OC(arg))
  6631.  
  6632. @<Part 2@>=@[
  6633.  
  6634. SRTN app_temp FCN((letter,arg))
  6635.     CONST outer_char letter[] C0("")@;
  6636.     CONST outer_char arg[] C1("")@;
  6637. {
  6638. char temp[50];
  6639.  
  6640. sprintf(temp,"\\W%s:%s:",letter,arg);
  6641. APP_STR(temp);
  6642. }
  6643.  
  6644. @ This nucleus appends stuff for the preprocessor commands, macro
  6645. definitions, formats, etc.
  6646.  
  6647. @<Part 2@>=@[
  6648.  
  6649. SRTN app_proc FCN((next_control))
  6650.     eight_bits next_control C1("")@;
  6651. {
  6652. if(the_part == DEFINITION) 
  6653.     {
  6654.     @<Append \.{\\WP}@>@;
  6655.  
  6656.     if(yskipped)
  6657.         {
  6658.         @<Append the scrap header for the definition part@>@;
  6659.         yskipped = NO;
  6660.         }
  6661.     }
  6662.  
  6663. switch(next_control)
  6664.     {
  6665.    case WEB_definition:  // ``\.{@@m}''
  6666.     APP_STR(upper_case_code ? "\\WMD" : "\\WMd"); @+ break;
  6667.  
  6668.    case undefinition: // ``\.{@@u}''
  6669.     APP_LANG("Ud"); @+ break;
  6670.     
  6671.    case definition:  // ``\.{@@d}''
  6672.     APP_LANG(upper_case_code ? "D" : "d"); @+ break; 
  6673.  
  6674.    case formatt: // ``\.{@@f}''
  6675.     APP_LANG("F"); @+ break;
  6676.  
  6677.    case limbo_text: // ``\.{@@l}''
  6678.     APP_LANG("l"); @+ break;
  6679.  
  6680.    case op_def: // ``\.{@@v}''
  6681.     APP_LANG("v"); @+ break;
  6682.  
  6683.    case macro_def:  // `\.{@@w}'.
  6684.     APP_LANG(upper_case_code ? "WW" : "w"); @+ break;
  6685.  
  6686.    case m_ifdef:
  6687.     APP_TEMP("E","ifdef"); @+ break;
  6688.  
  6689.    case m_ifndef:
  6690.     APP_TEMP("E","ifndef"); @+ break;
  6691.  
  6692.    case m_pragma:
  6693.     APP_TEMP("E","pragma"); @+ break;
  6694.  
  6695.    case m_undef:
  6696.     APP_TEMP("E","undef"); @+ break;
  6697.  
  6698.    case m_if:
  6699.     APP_TEMP("E","if"); @+ break;
  6700.  
  6701.    case m_elif:
  6702.     APP_TEMP("E","elif"); @+ break;
  6703.  
  6704.    case m_else:
  6705.     APP_TEMP("E","else"); 
  6706.     app_scrap(ignore_scrap,no_math);
  6707.     break;
  6708.  
  6709.    case m_for:
  6710.     APP_TEMP("E","for"); @+ break;
  6711.  
  6712.    case m_endfor:
  6713.     APP_TEMP("E","endfor");
  6714.     app_scrap(ignore_scrap,no_math);
  6715.     break;
  6716.  
  6717.    case m_endif:
  6718.     APP_TEMP("E","endif");
  6719.     app_scrap(ignore_scrap,no_math);
  6720.     break;
  6721.     }
  6722. @.\\WD@>
  6723. @.\\WMD@>
  6724. @.\\WE@>
  6725. }
  6726.  
  6727. @ This function helps keep the code short.
  6728.  
  6729. @d APP_LANG(suffix) app_lang(OC(suffix))
  6730.  
  6731. @<Part 2@>=@[
  6732.  
  6733. SRTN app_lang FCN((suffix))
  6734.     CONST outer_char *suffix C1("")@;
  6735. {
  6736. APP_TEMP(suffix,(CONST outer_char *)(language_symbol(language)));
  6737. }
  6738.  
  6739. @ Macro definitions have the syntax `\.{@@m\ A\ b}' or `\.{@@m\ A(x)\ y}'.
  6740. Keeping in line with the conventions of the C and~\.{WEB} preprocessors
  6741. (and otherwise contrary to the rules of \.{WEB}) we distinguish here
  6742. between the case that `\.('~immediately follows an identifier and the case
  6743. that the two are separated by a space.  In the latter case, and if the
  6744. identifier is not followed by~`\.(' at all, the replacement text starts
  6745. immediately after the identifier.  In the former case, it starts after we
  6746. scan the matching~`\.)'.
  6747.  
  6748. @<Start a macro...@>= 
  6749. {
  6750. LANGUAGE saved_language = language;
  6751.  
  6752. if(next_control == definition)
  6753.     SUPPRESS(outer_macros);
  6754.  
  6755. if(next_control == WEB_definition)
  6756.     SUPPRESS(macros);
  6757.  
  6758. app_proc(next_control);
  6759.  
  6760. if(language==TEX) 
  6761.     language = C;
  6762.  
  6763. if( ((C_LIKE(language) || language==LITERAL) &&
  6764.         next_control<=WEB_definition) || 
  6765.         next_control==WEB_definition || 
  6766.         next_control==m_ifdef || 
  6767.         next_control==m_ifndef || next_control==m_undef)
  6768.     {
  6769.     if( (next_control=get_next())!=identifier && next_control != @'[')
  6770.         {
  6771.         ERR_PRINT(W,"Improper macro definition: \
  6772. expected identifier");
  6773. @.Improper macro definition@>
  6774.         }
  6775.     else 
  6776.         {
  6777.         if(next_control == @'[') 
  6778.             @<Format auto insertion@>@;
  6779.  
  6780.         app(@'$'); APP_ID;
  6781.  
  6782.         if (*loc==@'(') 
  6783.             @<Append argument of \WEB\ macro@>@;
  6784.          else /* Id not followed by parenthesis. */
  6785.             {
  6786.             next_control=get_next();
  6787.             }
  6788.  
  6789.         app(@'$'); app(break_space);
  6790.         app_scrap(ignore_scrap,no_math); /* scrap won't take part in
  6791.                         the parsing */ 
  6792.         }
  6793.     }
  6794. else 
  6795.     next_control = get_next(); 
  6796.  
  6797. if(saved_language == TEX)
  6798.     language = saved_language;
  6799. }
  6800.  
  6801. @
  6802. @<Format auto insert...@>=
  6803. {
  6804. APP_STR("\\Wauto");
  6805. get_string(@'[','\0');
  6806. *id_loc = '\0';
  6807. app_ASCII_str(id_first);
  6808. next_control = get_next();
  6809. }
  6810.  
  6811. @
  6812. @<Append argument of \WEB\ macro@>=
  6813. {
  6814. reswitch: 
  6815.   next_control = get_next();
  6816. the_switch:
  6817.   switch(next_control)
  6818.     {
  6819.       case @'(': 
  6820.     app(next_control);
  6821.     next_control = get_next();
  6822.     if(next_control == @')')
  6823.         {
  6824.         b_app(@'\\'); @+ b_app(@','); // Extra thinspace for beauty.
  6825.         goto done_arg;
  6826.         }
  6827.     else goto the_switch;
  6828.  
  6829.       case @',': 
  6830.     app(next_control); goto reswitch;
  6831.  
  6832.       case identifier: 
  6833.     APP_ID;
  6834.     goto reswitch; 
  6835.  
  6836.       case ellipsis:
  6837.     APP_STR("\\dots");
  6838.     if( (next_control=get_next()) != @')')
  6839.         {
  6840.         ERR_PRINT(M,"Improper macro \
  6841. definition: expected ')' after ellipsis");
  6842.         break;
  6843.         }
  6844.  
  6845.       case @')': 
  6846.        done_arg:
  6847.     app(next_control); app(@' ');
  6848.     next_control=get_next(); break; 
  6849.  
  6850.       default: 
  6851.     ERR_PRINT(M,"Improper macro definition: \
  6852. unrecognized token in argument list"); 
  6853.     break;
  6854.     }
  6855. }
  6856.  
  6857. @ Here we append a format command, which has the two possible forms
  6858. ``\.{@@f\ a\ b}'' or ``\.{@@f\ `\{\ 11}''.
  6859.  
  6860. @<Start a format...@>= 
  6861. {
  6862. LANGUAGE saved_language = language;
  6863. scrap_pointer scrp_ptr0;
  6864.  
  6865. SUPPRESS(formats);
  6866.  
  6867. /* Mark formats that are not in the global language. */
  6868. app_proc(next_control); // |formatt|.
  6869. scrp_ptr0 = scrp_ptr; // Save to help check valid format.
  6870. app_scrap(expr,maybe_math); /* this will produce `\&{format}'. The
  6871.     macro inserts a blank after \&{format}. */
  6872. @.\\WF@>
  6873.  
  6874. if(language==TEX) 
  6875.     language = C; // This kludge ought to be removed!
  6876.  
  6877. next_control=get_next(); /* First field: identifier, module name, or~'\.`'. */
  6878.  
  6879. if (next_control==identifier || next_control==module_name) 
  6880.     @<Format an identifier or module name@>@;
  6881. else if(next_control==@'`')
  6882.     @<Format a category code@>@;
  6883.  
  6884. if (scrp_ptr!=scrp_ptr0+3) 
  6885.     ERR_PRINT(W,"Improper format definition");
  6886. @.Improper format definition@>
  6887.  
  6888. /* The following doesn't work right if the format command is immediately
  6889. followed by a language-changing command. */
  6890. if(saved_language == TEX)
  6891.     language = saved_language;
  6892. }
  6893.  
  6894. @
  6895. @<Format an identifier or mod...@>=
  6896. {
  6897. if(next_control==identifier) 
  6898.     APP_ID;
  6899. else 
  6900.     APP_FLAG(mod,cur_module,name_dir);
  6901.  
  6902. APP_STR("\\ ");
  6903.  
  6904. next_control=get_next(); /* Second field: identifier. */
  6905.  
  6906. if (next_control==identifier) 
  6907.     {
  6908.     APP_ID;
  6909.     @<Finish appending format definition@>@;
  6910.     }
  6911. }
  6912.  
  6913. @
  6914. @<Finish appending format...@>=
  6915. {
  6916. app_scrap(expr,maybe_math); 
  6917. app_scrap(semi,maybe_math); // Pseudo-semi.
  6918.  
  6919. sharp_include_line = NO;
  6920.  
  6921. next_control=get_next();
  6922. }
  6923.  
  6924. @ Here we typeset a format command that changes a category code, such as
  6925. ``\.{@@f\ `a\ 10}''.
  6926.  
  6927. @<Format a cat...@>=
  6928. {
  6929. @<Append commands for beginning of string@>@;
  6930. app(@'`');
  6931. if( (next_control = get_TeX()) == constant)
  6932.     APP_STR((outer_char *)id_first);
  6933. app(@'}');
  6934.  
  6935. APP_STR("\\ ");
  6936.  
  6937. next_control = get_next(); // Integer category code.
  6938.  
  6939. if(next_control == constant)
  6940.     {
  6941.     APP_STR("\\WO{");
  6942.  
  6943.     while(id_first < id_loc)
  6944.         app_tok(*id_first++);
  6945.  
  6946.     app(@'}');
  6947.  
  6948.     @<Finish appending format...@>@;
  6949.     }
  6950. }
  6951.  
  6952. @ Here we append a limbo text definition of the form ``\.{@@l\ "text"}''.
  6953.  
  6954. @<Start a limbo...@>=
  6955. {
  6956. SUPPRESS(limbo);
  6957.  
  6958. app_proc(next_control);
  6959. app_scrap(expr,maybe_math);
  6960.  
  6961. /* First field: String. */
  6962. if((next_control = get_next()) != stringg)
  6963.     ERR_PRINT(W,"A string must follow @@l"); 
  6964. }
  6965.  
  6966. @ Here we append an operator-overload command, of the form ``\.{@@v\ .IN.\
  6967. "\\\\in"\ +}''.
  6968.  
  6969. @<Start an overloaded op...@>=
  6970. {
  6971. SUPPRESS(v);
  6972.  
  6973. overload_ops = NO;
  6974.  
  6975. app_proc(next_control);
  6976. app_scrap(expr,maybe_math);
  6977.  
  6978. /* First field: The operator to be overloaded. */
  6979. if(valid_op(next_control = get_next()))
  6980.     {
  6981.     @<Append an operator name@>@;
  6982.  
  6983.     app(@' '); @+ app_scrap(expr,no_math);
  6984.  
  6985.  /* Second field: Replacement text. */
  6986.     if((next_control = get_next()) == stringg)
  6987.         {
  6988.         @<Append commands for beginning of string@>@;
  6989.         @<Append the basic str...@>@;
  6990.         app_scrap(expr,yes_math);
  6991.  
  6992.     /* Third field: Cat of this operator. */
  6993.         if(valid_op(next_control=get_next()))
  6994.             {
  6995.             app(@' '); @+ app_scrap(expr,no_math);
  6996.  
  6997.             @<Append an operator...@>@;        
  6998.  
  6999.             next_control = get_next();
  7000.             }
  7001.         }
  7002.     }
  7003. }
  7004.  
  7005. @ The last field of an \.{@@v}~command can be either an operator like~`\.+'
  7006. or an identifier like~`\.{.IN.}'.
  7007.  
  7008. @<Append an operator...@>=
  7009. {
  7010. switch(next_control)
  7011.     {
  7012.    case identifier:
  7013.     ERR_PRINT(W,"For future compatibility, please use syntax .NAME. for \
  7014. overloading dot operators");
  7015.  
  7016.     APP_ID;
  7017.     break;
  7018.  
  7019.    case dot_const:
  7020.     @<Append commands for beginning of string@>@;
  7021.     app(wt_style.dot_delimiter.begin);
  7022.     app_ASCII_str(dot_op.name + 1);
  7023.     app(wt_style.dot_delimiter.end);
  7024.     app(@'}');
  7025.     break;
  7026.  
  7027.    default:
  7028.     app(@'{'); 
  7029.     app_overload();
  7030.     app(@'}');
  7031.     break;
  7032.     }
  7033.  
  7034. app_scrap(expr,yes_math);
  7035. }
  7036.  
  7037. @
  7038. @<Start an overloaded id...@>=
  7039. {
  7040. SUPPRESS(w);
  7041.  
  7042. app_proc(next_control);
  7043. app_scrap(expr,maybe_math);
  7044.  
  7045. /* First field:  The identifier to be overloaded. */
  7046. if((next_control = get_next()) == identifier)
  7047.     {
  7048.     ASCII HUGE *id_first0, HUGE *id_loc0;
  7049.  
  7050. /* Remember first identifier. */
  7051.     id_first0 = id_first;
  7052.     id_loc0 = id_loc;
  7053.  
  7054.     APP_ID;
  7055.  
  7056.     app(@' '); @+ app_scrap(expr,no_math);
  7057.  
  7058. /* Second field:  Replacement text. */
  7059.     switch(next_control = get_next())
  7060.         {
  7061.        case @'\\':
  7062.         if((next_control=get_next()) != identifier) break;
  7063.         goto quick_code1;
  7064.  
  7065.        case QUICK_FORMAT:
  7066.         id_first = id_first0;
  7067.         id_loc = id_loc0;
  7068.  
  7069.     quick_code1:
  7070.         @<Append commands for beginning of string@>@;
  7071.         APP_STR("\\\\");
  7072.         *id_loc = '\0'; // Make name into string.
  7073.         app_ASCII_str(id_first);
  7074.         app(@'}');
  7075.         app_scrap(expr,yes_math);
  7076.         next_control = get_next();
  7077.         break;
  7078.  
  7079.        case stringg:
  7080.         @<Append commands for beginning of string@>@;
  7081.         @<Append the basic str...@>@;
  7082.         app_scrap(expr,yes_math);
  7083.         next_control = get_next();
  7084.         break;
  7085.         }
  7086.     }
  7087. }
  7088.  
  7089. @ Finally, when the \TeX\ and definition parts have been treated, we have
  7090. |next_control>=begin_code|. We will make the global variable |this_module|
  7091. point to the current module name, if it has a name; otherwise, it will be
  7092. equal to |name_dir|.
  7093.  
  7094. @<Global...@>=
  7095.  
  7096. EXTERN name_pointer this_module; // The current module name, or zero.
  7097. EXTERN name_pointer the_module; /* The module we're working on; equal to
  7098.     |cur_module| at the beginning of the entire module. */
  7099.  
  7100. @<Part 2@>=@[
  7101.  
  7102. SRTN trns_code(VOID)
  7103. {
  7104. the_part = CODE;
  7105. this_module = name_dir;
  7106. parsing_mode = OUTER;
  7107.  
  7108. if (next_control<=module_name) 
  7109.     {
  7110. @%    emit_space_if_needed; 
  7111.     OUT_STR("\\WY");
  7112.     ini_stack;
  7113.     @<Store the output switch@>@;
  7114.     @<Append \.{\\WP}@>@;
  7115.  
  7116.     if (next_control==begin_code)
  7117.         { /* We've hit an \.{@@a}. */
  7118.         boolean nuweb_mode0 = nuweb_mode;
  7119.  
  7120.         params = global_params;// Unnamed module is in global language.
  7121.         nuweb_mode = nuweb_mode0;        
  7122.         frz_params();
  7123.         the_module = NULL;
  7124.         @<Maybe start column mode.@>@;
  7125.  
  7126.         @<Append the scrap header for code@>@; // !!!!!
  7127.         }
  7128.       else 
  7129.         { /* Named module. */
  7130.         if(cur_module != NULL) 
  7131.             {
  7132.             params = cur_module->mod_info->params;
  7133.                 // Restore state for this module.
  7134.             frz_params();
  7135.             this_module = cur_module;
  7136.             }
  7137.         the_module = cur_module;
  7138.         @<Check that |=| or |==| follows this module name, and
  7139.               emit the scraps to start the module definition@>;
  7140.         }
  7141.  
  7142. /* Now scan the whole module. */
  7143.       while  (next_control<=module_name) 
  7144.         {
  7145.         outr_parse();
  7146.         @<Emit the scrap for a module name if present@>;
  7147.         }
  7148.  
  7149.     @<Reset the language before translation@>@;
  7150.     fin_C();
  7151.     }
  7152. }
  7153.  
  7154. @
  7155. @<Append the scrap header for the definition part@>=
  7156. {
  7157. app_hdr("defs");
  7158. }
  7159.  
  7160. @
  7161. @<Append the scrap header for code@>=
  7162. {
  7163. app_hdr("code");
  7164. }
  7165.  
  7166. @ The scrap header needs the file name as argument to \.{\\Wunnamed}; it
  7167. must be escaped.  We use the |mod_text| buffer as a scratch area.
  7168.  
  7169. @<Part 2@>=@[
  7170.  
  7171. SRTN app_hdr FCN((section_part))
  7172.     CONST char *section_part C1("Either \"code\" or \"defs\"")@;
  7173. {
  7174. outer_char temp[1000], *temp_end = temp + 1000, *t_first, *t_loc;
  7175.  
  7176. t_first = temp;
  7177. STRCPY(t_first, params.OUT_FILE_NAME);
  7178. to_ASCII(t_first);
  7179. t_first = esc_buf((ASCII HUGE *)t_first+STRLEN(t_first)+1, 
  7180.     (ASCII HUGE *)temp_end, (CONST ASCII HUGE *)t_first, YES); 
  7181. to_outer((ASCII HUGE *)t_first);
  7182. t_loc = t_first + STRLEN(t_first) + 1;
  7183. sprintf((char *)t_loc, " \\Wunnamed{%s}{%s}%%\n", section_part, t_first);
  7184. APP_STR(t_loc);
  7185. app_scrap(ignore_scrap,no_math);
  7186. }
  7187.  
  7188. @<Check that |=|...@>=
  7189. {
  7190. LANGUAGE saved_language = language;
  7191.  
  7192. if(language==TEX) 
  7193.     language = C;
  7194.  
  7195. /* Allow optional `\.{+=}'. */
  7196. do 
  7197.     next_control=get_next();
  7198. while (next_control==@'+');
  7199.  
  7200. language = saved_language;
  7201.  
  7202. switch(next_control)
  7203.     {
  7204.    case compound_assignment:
  7205.     if(assignment_token != plus_eq)
  7206.         {
  7207.         ERR_PRINT(W,"Invalid compound assignment after section \
  7208. name; please use one of `=', `==', or `+='");
  7209. @.Invalid compound assignment...@>
  7210.         break;
  7211.         }
  7212.  
  7213. /* The |plus_eq| falls through to the next case. */
  7214.  
  7215.    case @'=':
  7216.    case eq_eq:
  7217.     @<Maybe start column mode.@>@; // Positioned after `\.{@@<\dots@@>=}'.
  7218.     break;
  7219.  
  7220.    default:
  7221.     ERR_PRINT(W,"You need an = sign after the section name");
  7222. @.You need an = sign...@>
  7223.     break;
  7224.     }
  7225.  
  7226. #if(0)
  7227. if (out_ptr>out_buf+2 && STRNCMP(out_ptr-2,"\\WY",3)==0)
  7228. #endif
  7229.     {
  7230.     app(backup);     /* The module name will be flush left */
  7231.     app(backup);
  7232.     }
  7233. @.\\WY@>
  7234.  
  7235. APP_FLAG(mod,this_module,name_dir);
  7236. cur_xref = (xref_pointer)this_module->xref;
  7237. APP_STR("${}");
  7238.  
  7239. if(cur_xref->num != module_count+def_flag) 
  7240.     {
  7241.     APP_STR("\\PQ"); // Module name is multiply defined,
  7242. @.\\PQ@>
  7243.     this_module=name_dir; // so we won't give cross-reference info here.
  7244.     }
  7245. else 
  7246.     APP_STR("\\WS"); // Output the equivalence sign~`$\equiv$'.
  7247. @.\\WS@>
  7248.  
  7249. APP_STR("{}$");
  7250. app_misc(w_style.misc.named_preamble); // Optional stuff from style file.
  7251. app(force); app_scrap(stmt,no_math); /* This forces a line break unless
  7252.                     `\.{@@+}' follows */ 
  7253. }
  7254.  
  7255. @ Because the language may have changed in the middle of a module, we must
  7256. reset it before we perform the translation of the scraps that have just
  7257. been collected.
  7258.  
  7259. @<Reset the language...@>=
  7260. {
  7261. params = (the_module == NULL ? global_params : the_module->mod_info->params);
  7262. frz_params();
  7263. }
  7264.  
  7265. @ When we append miscellaneous stuff from the style file, we must be a bit
  7266. clever.  If the stuff contains something like~`\.{\\7}' and we just
  7267. appended it raw, it wouldn't be subject to the later output mechanism that
  7268. takes the maximum of adjacent |force| and |big_force| tokens.  Thus, we
  7269. will translate the macros~`\.{\\1}' to~`\.{\\8}' into their internal tokens
  7270. before appending them.  Other text in the miscellaneous string is just left
  7271. alone.
  7272.  
  7273. @<Part 2@>=@[
  7274.  
  7275. SRTN app_misc FCN((s))
  7276.     outer_char *s C1("")@;
  7277. {
  7278. outer_char *s0;
  7279.  
  7280. for(s0=s; *s; )
  7281.     if(*s++ == '\\')
  7282.         {
  7283.         if(isdigit(*s) && *s != '0' && *s != '8' && *s != '9')
  7284.             {
  7285.             *(s-1) = '\0'; // Terminate for |app_str|.
  7286.             APP_STR(s0);
  7287.  
  7288.             switch(*s)
  7289.                 {
  7290.                case '1': app(indent); @+ break;
  7291.                case '2': app(outdent); @+ break;
  7292.                case '3': app(opt); @+ break;
  7293.                case '4': app(backup); @+ break;
  7294.                case '5': app(break_space); @+ break;
  7295.                case '6': app(force); @+ break;
  7296.                case '7': app(big_force); @+ break;
  7297.                 }
  7298.             *(s-1) = '\\'; // Put it back for the next time.
  7299.             s0 = ++s; // Skip the digit.
  7300.             }
  7301.         }
  7302.  
  7303. APP_STR(s0);
  7304. }
  7305.  
  7306. @<Maybe start column mode.@>=
  7307. {
  7308. if(!nuweb_mode && ((FORTRAN_LIKE(language) && !free_form_input) 
  7309.         || (language==TEX)) ) 
  7310.     {
  7311.     @<Set up column mode@>@;
  7312.     next_control = ignore;
  7313.     }
  7314. else
  7315.     {
  7316.     @<Kill rest of line; no |auto_semi|@>@;
  7317.     next_control = (nuweb_mode ? begin_meta : get_next()); // !!!!!
  7318.     }
  7319. }
  7320.  
  7321. @
  7322. @<Kill rest of line; no...@>=
  7323.  
  7324. if(Fortran88 && auto_semi)
  7325.     {
  7326.     loc = limit + 1;
  7327.     chk_end = NO;
  7328.     }
  7329.  
  7330.  
  7331. @ When shifting into \FORTRAN\ mode, we skip any stuff on the same line as
  7332. the~\.{@@n}, because surely that text isn't in the appropriate columns.
  7333. @<Set up col...@>=
  7334. {
  7335. loc = limit + 1; // Skip rest of line.
  7336. chk_end = NO;
  7337. column_mode = YES;
  7338. }
  7339.  
  7340. @<Emit the scrap...@>=
  7341.  
  7342. if (next_control<module_name) 
  7343.     {
  7344.     switch(next_control)
  7345.         {
  7346.         case m_if: case m_ifdef: case m_ifndef: 
  7347.         case m_undef: case m_else: 
  7348.         case m_elif: case m_endif: 
  7349.         case m_for: case m_endfor:
  7350.         case m_pragma:
  7351.         case WEB_definition:
  7352.             pre_scrap(next_control);
  7353.             break;
  7354.  
  7355.         default:
  7356.               ERR_PRINT(W,"You can't do that in code text");
  7357. @.You can't do that...@>
  7358.             break;
  7359.         }
  7360.       next_control=get_next();
  7361.     }
  7362. else if (next_control==module_name) 
  7363.     {
  7364.     @<Append a module name@>@;
  7365.     next_control = (nuweb_mode ? begin_meta : get_next()); // !!!!!
  7366.     }
  7367.  
  7368. @ Tack on the representation of a module name.
  7369. @<Append a mod...@>=
  7370. {
  7371. if(cur_module) 
  7372.     APP_FLAG(mod,cur_module,name_dir);
  7373. app_scrap(cur_module != NULL ? cur_module->mod_ilk : expr,maybe_math); 
  7374. }
  7375.  
  7376. @ Build a preprocessor scrap.
  7377. @<Part 2@>=@[
  7378.  
  7379. SRTN pre_scrap FCN((last_control))
  7380.     eight_bits last_control C1("")@;
  7381. {
  7382. scrap_pointer save_base;
  7383. text_pointer p,q;
  7384. LANGUAGE saved_language = language;
  7385.  
  7386. app(force); 
  7387. app_proc(last_control);
  7388.  
  7389. switch(last_control)
  7390.     {
  7391.     case WEB_definition:
  7392.         @<Start a deferred macro definition@>;
  7393.         break;
  7394.     }
  7395.  
  7396. p = text_ptr; freeze_text;
  7397.  
  7398. save_base = scrp_base;
  7399. scrp_base = scrp_ptr + 1;
  7400.  
  7401. *limit = @'@@'; @+ *(limit+1) = @'m'; /* Stop the |outr_parse|. */
  7402. next_control = ignore;
  7403.  
  7404. if(language==TEX) language = C;
  7405.     outr_parse();
  7406. language = saved_language;
  7407.  
  7408. if(last_control==WEB_definition) {app_scrap(semi,maybe_math);}
  7409.  
  7410. q = translate(OUTER);
  7411. scrp_ptr = scrp_base - 1;
  7412. scrp_base = save_base;
  7413.  
  7414. APP_FLAG(tok,p,tok_start);
  7415. APP_FLAG(tok,q,tok_start);
  7416. APP_STR("\\WPs"); app(force); // Terminate preprocessor command.
  7417. app_scrap(ignore_scrap,no_math);
  7418. }
  7419.  
  7420. @
  7421. @<Start a deferred macro...@>=
  7422. {
  7423. if( (next_control=get_next())!=identifier)
  7424.            ERR_PRINT(M,"Improper deferred macro definition: \
  7425. expected identifier");
  7426. @.Improper macro definition@>
  7427. else 
  7428.     {
  7429.     app(@'$'); APP_ID;
  7430.  
  7431.     if (*loc==@'(')
  7432.         {
  7433.       reswitch: switch (next_control=get_next()) 
  7434.         {
  7435.           case @'(': case @',': 
  7436.             app(next_control); goto reswitch;
  7437.           case identifier: 
  7438.             APP_ID;
  7439.             goto reswitch; 
  7440.               case ellipsis:
  7441.                 APP_STR("\\dots");
  7442.                 if( (next_control=get_next()) != @')')
  7443.                     {
  7444.                     ERR_PRINT(M,"Improper deferred macro \
  7445. definition: expected ')' after ellipsis");
  7446.                     break;
  7447.                     }
  7448.           case @')': app(next_control); app(@' ');
  7449.             break; 
  7450.           default: ERR_PRINT(M,"Improper deferred macro definition: \
  7451. unrecognized token within argument list"); break;
  7452.          }
  7453.         }
  7454.  
  7455.     app(@'$'); app(break_space);
  7456.     app_scrap(ignore_scrap,no_math); /* scrap won't take part 
  7457.                     in the parsing */ 
  7458.     }
  7459. }
  7460.  
  7461. @ Cross references relating to a named module are given after the module ends.
  7462.  
  7463. @<Show cross...@>=
  7464.  
  7465. if (this_module>name_dir) 
  7466.     {
  7467.   @<Rearrange the list pointed to by |cur_xref|@>;
  7468.   footnote(def_flag); footnote(0);
  7469.     }
  7470.  
  7471. @ To rearrange the order of the linked list of cross-references, we need
  7472. four more variables that point to cross-reference entries.  We'll end up
  7473. with a list pointed to by |cur_xref|.
  7474.  
  7475. @<Global...@>=
  7476.  
  7477. EXTERN xref_pointer next_xref, this_xref, first_xref, mid_xref;
  7478.   /* Pointer variables for rearranging a list */
  7479.  
  7480. @ We want to rearrange the cross-reference list so that all the entries
  7481. with |def_flag| come first, in ascending order; then come all the other
  7482. entries, in ascending order.  There may be no entries in either one or both
  7483. of these categories.
  7484.  
  7485. @<Rearrange the list...@>=
  7486.  
  7487.   first_xref = (xref_pointer)this_module->xref;
  7488.   this_xref=first_xref->xlink; /* Bypass current module number */
  7489.  
  7490.   if (this_xref->num>def_flag) 
  7491.     {
  7492.         mid_xref=this_xref; cur_xref=0; /* This value doesn't matter */
  7493.  
  7494.       do 
  7495.         {
  7496.             next_xref=this_xref->xlink; this_xref->xlink=cur_xref;
  7497.             cur_xref=this_xref; this_xref=next_xref;
  7498.           } 
  7499.     while (this_xref->num>def_flag);
  7500.  
  7501.       first_xref->xlink=cur_xref;
  7502.     }
  7503. else mid_xref=xmem; /* First list null */
  7504.  
  7505. cur_xref=xmem;
  7506.  
  7507. while (this_xref!=xmem) 
  7508.     {
  7509.       next_xref=this_xref->xlink; this_xref->xlink=cur_xref;
  7510.       cur_xref=this_xref; this_xref=next_xref;
  7511.     }
  7512.  
  7513. if (mid_xref>xmem) mid_xref->xlink=cur_xref;
  7514. else first_xref->xlink=cur_xref;
  7515.  
  7516. cur_xref=first_xref->xlink;
  7517.  
  7518. @ The |footnote| procedure gives cross-reference information about multiply
  7519. defined module names (if the |flag| parameter is |def_flag|), or about the
  7520. uses of a module name (if the |flag| parameter is zero). It assumes that
  7521. |cur_xref| points to the first cross-reference entry of interest, and it
  7522. leaves |cur_xref| pointing to the first element not printed.  Typical
  7523. outputs: `\.{\\WA\ section 101.}'; `\.{\\WU\ sections 370 and 1009.}';
  7524. `\.{\\WA\ sections 8, 27\\*, and 64.}'.
  7525.  
  7526. @<Part 3@>=@[
  7527.  
  7528. SRTN footnote FCN((flag)) /* Outputs module cross-references */
  7529.     sixteen_bits flag C1("")@;
  7530. {
  7531.   xref_pointer q; /* Cross-reference pointer variable */
  7532.  
  7533.   if (cur_xref->num<=flag) return;
  7534.  
  7535.   fin_line(); OUT_STR("\\W");
  7536. @.\\WA@>
  7537. @.\\WU@>
  7538.  
  7539.   out( flag==0 ? @'U' : @'A');
  7540.  
  7541.   OUT_STR(" section");
  7542.   @<Output all the module numbers on the reference list |cur_xref|@>;
  7543.   out(@'.');
  7544. }
  7545.  
  7546. @ The following code distinguishes three cases, according as the number of
  7547. cross-references is one, two, or more than two. Variable~|q| points to the
  7548. first cross-reference, and the last link is a zero.
  7549.  
  7550. @<Output all the module numbers...@>=
  7551.  
  7552. q=cur_xref; if (q->xlink->num>flag) out(@'s'); // Pluralize.
  7553. out(@'~');
  7554.  
  7555. WHILE()
  7556.     {
  7557.   out_mod(cur_xref->num-flag,ENCAP);
  7558.   cur_xref=cur_xref->xlink; /* Point to the next cross-reference to output */
  7559.  
  7560.   if (cur_xref->num<=flag) break;
  7561.  
  7562.   if (cur_xref->xlink->num>flag || cur_xref!=q->xlink) out(@',');
  7563.     /* Not the last of two */
  7564.  
  7565.   out(@' ');
  7566.  
  7567.   if (cur_xref->xlink->num<=flag) OUT_STR("and~"); /* the last */
  7568.     }
  7569.  
  7570. @<Output the code for the end of a module@>=
  7571. {
  7572. if(in_module && output_on)
  7573.     {
  7574.     outer_char temp[100];
  7575.  
  7576.     SPRINTF(100,temp,`"\\fi %% End of module %u",(unsigned)module_count`);
  7577.     OUT_STR(temp); @+ fin_line();
  7578. @.\\fi@>
  7579.     in_module = NO;
  7580.  
  7581.     flush_buffer(out_buf,NO); // Insert a blank line for beauty.
  7582.     }
  7583. }
  7584.  
  7585. @* PHASE THREE PROCESSING.  We are nearly finished! \.{WEAVE}'s only
  7586. remaining task is to write out the index and module list, after sorting the
  7587. identifiers and index entries.  The index and module list are written into
  7588. separate files, by default \.{INDEX.tex} and \.{MODULES.tex}.
  7589.  
  7590. If the user has set the |no_xref| flag (the \.{-x} option on the command
  7591. line), just finish off the page, omitting the index, module name list, and
  7592. table of contents.  (Fix this up.)
  7593.  
  7594. @d NEW_TeX(file_name) 
  7595.     if(tex_file != stdout)
  7596.         {
  7597.         fclose(tex_file);
  7598.         if((tex_file=FOPEN(file_name,"w"))==NULL)
  7599.             FATAL("! Can't open output file ",file_name);
  7600.         }
  7601.  
  7602. @<Part 3@>=@[
  7603.  
  7604. SRTN phase3(VOID) 
  7605. {
  7606. language = global_language;
  7607.  
  7608. if (no_xref && !prn_contents) 
  7609.     {
  7610.     fin_line();
  7611.     @<Finish off |phase3|@>@;
  7612.     }
  7613. else 
  7614.     { // Print cross-reference information.
  7615.     outer_char HUGE *temp_ndx,HUGE *temp_mds;
  7616.     IN_COMMON outer_char wbflnm0[];
  7617.  
  7618.     temp_ndx = GET_MEM("temp_ndx",MAX_FILE_NAME_LENGTH,outer_char);
  7619.     temp_mds = GET_MEM("temp_mds",MAX_FILE_NAME_LENGTH,outer_char);
  7620.  
  7621.     phase = 3; 
  7622.     nuweb_mode = NO; // Force full output of identifiers.
  7623.  
  7624.     if(prn_index)
  7625.         {
  7626.         OUT_STR("\\input "); 
  7627.         OUT_STR(xpn_name(&temp_ndx,MAX_FILE_NAME_LENGTH,
  7628.             w_style.indx.tex,wbflnm0));
  7629.         fin_line();
  7630.         }
  7631.  
  7632.     if(prn_modules)
  7633.         {
  7634.         OUT_STR("\\input "); 
  7635.         OUT_STR(xpn_name(&temp_mds,MAX_FILE_NAME_LENGTH,
  7636.             w_style.modules.tex,wbflnm0)); 
  7637.         fin_line(); 
  7638.  
  7639.         fin_line();
  7640.  
  7641.         @<Print the command line, etc.@>; 
  7642. @.\\Winfo@>
  7643.         }
  7644.  
  7645.     if(prn_contents)
  7646.         {
  7647.         OUT_STR(w_style.contents.preamble); 
  7648.         OUT_STR(w_style.contents.postamble); 
  7649.         fin_line();
  7650. @.\\Wcon@>
  7651.         }
  7652.     else @<Finish off |phase3|@>@;
  7653.  
  7654.     if(prn_index) @<Output the index@>@;
  7655.     if(prn_modules) @<Output all the module names@>@;
  7656.  
  7657.     if(tex_file != stdout) fclose(tex_file);
  7658.     }
  7659.  
  7660. CLR_PRINTF(info,("\nDone."));
  7661. chk_complete(); /* Was all of the change file used? */
  7662. }
  7663.  
  7664. @
  7665. @<Finish off |phase3|@>=
  7666. {
  7667. OUT_STR("\\vfill\\FWEBend"); @+ fin_line();
  7668. }
  7669.  
  7670. @
  7671.  
  7672. @d N_CMD 1000
  7673.  
  7674. @<Print the command line...@>=
  7675. @{
  7676. outer_char HUGE *temp;
  7677.  
  7678. @b
  7679. temp = GET_MEM("temp",N_CMD,outer_char);
  7680.  
  7681. OUT_STR(w_style.modules.info);
  7682. OUT_STR(cmd_ln_buf); @+ fin_line();
  7683.  
  7684. /* Print a message identifying the global language. */
  7685. SPRINTF(N_CMD,temp,`" {%s}",language_name_ptr(global_language)`);
  7686. OUT_STR(temp); @+ fin_line();
  7687.  
  7688. FREE_MEM(temp,"temp",N_CMD,outer_char);
  7689. }
  7690.  
  7691.  
  7692. @ Here we escape an |ASCII| string into another buffer.  We return the
  7693. beginning of the output buffer.
  7694.  
  7695. @d TO_TEMP(val) if(temp < temp_end) *temp++ = val; 
  7696.         else OVERFLW("Esc_buf:temp","") 
  7697.  
  7698. @<Part 3@>=@[
  7699.  
  7700. ASCII HUGE *esc_buf FCN((temp,temp_end,buf,all_cases))
  7701.     ASCII HUGE *temp C0("Put it into here.")@;
  7702.     CONST ASCII HUGE *temp_end C0("End of |temp|.")@;
  7703.     CONST ASCII HUGE *buf C0("Translate from here.")@;
  7704.     boolean all_cases C1("")@;
  7705. {
  7706. ASCII HUGE *temp0 = temp;
  7707.  
  7708. while(*buf != '\0')
  7709.     {
  7710.     switch(*buf)
  7711.         {
  7712.         @<Special \TeX\ cases@>:
  7713.             if(!all_cases) break;
  7714.  
  7715.         @<Other string cases@>:
  7716.             TO_TEMP(@'\\');
  7717.             break;
  7718.         }
  7719.  
  7720.     TO_TEMP(*buf++);
  7721.     }
  7722.  
  7723. TO_TEMP('\0');
  7724. return temp0; // Return the beginning of the output buffer.
  7725. }
  7726.  
  7727. @ Just before the index comes a list of all the changed modules, including
  7728. the index module itself.
  7729.  
  7730. @<Global...@>=
  7731.  
  7732. EXTERN sixteen_bits k_module; /* Runs through the modules */
  7733.  
  7734. @<Tell about changed modules@>= 
  7735.     {
  7736.   /* Remember that the index is already marked as changed */
  7737.       k_module=0;
  7738.  
  7739.       while (!chngd_module[++k_module]);
  7740.  
  7741.       OUT_STR("\\Wch ");
  7742. @.\\Wch@>
  7743.       out_mod(k_module,ENCAP);
  7744.  
  7745.       while (k_module < module_count)
  7746.         {
  7747.             while (!chngd_module[++k_module]); /* Skip over
  7748. unchanged modules. */
  7749.  
  7750.             OUT_STR(", "); out_mod(k_module,ENCAP);
  7751.           }
  7752.  
  7753.   out(@'.');
  7754. }
  7755.  
  7756. @ A left-to-right radix sorting method is used, since this makes it easy to
  7757. adjust the collating sequence and since the running time will be at worst
  7758. proportional to the total length of all entries in the index. We put the
  7759. identifiers into different lists based on their first characters.
  7760. (Uppercase letters are put into the same list as the corresponding
  7761. lowercase letters, since we want to have `$t<\\{TeX}<\&{to}$'.) The list
  7762. for character~|c| begins at location |bucket[c]| and continues through the
  7763. |blink| array.
  7764.  
  7765. @<Global...@>=
  7766.  
  7767. EXTERN name_pointer bucket[128]; // One for each standard |ASCII char|.
  7768. EXTERN name_pointer next_name; /* Successor of |cur_name| when sorting */
  7769. IN_COMMON hash_pointer h; /* Index into |hash| */
  7770.  
  7771. IN_COMMON BUF_SIZE max_names; /* number of identifiers, strings, module names;
  7772.   must be less than~10240 */
  7773. EXTERN name_pointer HUGE *blink; /* Links in the buckets */
  7774. EXTERN ASCII last_letter SET('\0'); /* Used for separating groups in the
  7775.                     index. */ 
  7776.  
  7777. @
  7778. @<Alloc...@>=
  7779.  
  7780. ALLOC(name_pointer,blink,ABBREV(max_names),max_names,0);
  7781.  
  7782. @ To begin the sorting, we go through all the hash lists and put each entry
  7783. having a nonempty cross-reference list into the proper bucket.
  7784.  
  7785. @<Do the first pass of sorting@>= 
  7786. @{
  7787. int c;
  7788.  
  7789. @b
  7790. for (c=0; c<=127; c++) bucket[c]=NULL;
  7791.  
  7792. for (h=hash; h<=hash_end; h++) 
  7793.     {
  7794.       next_name=*h;
  7795.  
  7796.       while (next_name) 
  7797.         {
  7798.             cur_name=next_name; next_name=cur_name->link;
  7799.  
  7800.             if ((xref_pointer)cur_name->xref != xmem) 
  7801.             {
  7802.                   c=(cur_name->byte_start)[0];
  7803.  
  7804.                 c = A_TO_LOWER(c);
  7805.  
  7806.                   blink[cur_name-name_dir]=bucket[c];
  7807.                 bucket[c]=cur_name; 
  7808.              }
  7809.         }
  7810.     }
  7811. }
  7812.  
  7813. @ During the sorting phase we shall use the |cat| and |trans| arrays from
  7814. \.{WEAVE}'s parsing algorithm and rename them |depth| and |head|. They now
  7815. represent a stack of identifier lists for all the index entries that have
  7816. not yet been output. The variable |sort_ptr| tells how many such lists are
  7817. present; the lists are output in reverse order (first |sort_ptr|, then
  7818. |sort_ptr-1|, etc.). The |j|th list starts at |head[j]|, and if the first
  7819. |k| characters of all entries on this list are known to be equal we have
  7820. |depth[j]=k|.
  7821.  
  7822. @<Rest of |trans_plus| union@>=
  7823.  
  7824. name_pointer Head;
  7825.  
  7826. @
  7827. @f sort_pointer scrap_pointer
  7828.  
  7829. @d depth cat /* reclaims memory that is no longer needed for parsing */
  7830. @d head trans_plus.Head /* ditto */
  7831. @d sort_pointer scrap_pointer /* ditto */
  7832. @d sort_ptr scrp_ptr /* ditto */
  7833. @d max_sorts max_scraps /* ditto */
  7834.  
  7835. @<Global...@>=
  7836.  
  7837. EXTERN eight_bits cur_depth; /* Depth of current buckets */
  7838. EXTERN ASCII HUGE *cur_byte; /* Index into |byte_mem| */
  7839. EXTERN sixteen_bits cur_val; /* Current cross-reference number */
  7840.  
  7841. EXTERN sort_pointer mx_sort_ptr; /* largest value of |sort_ptr| */
  7842.  
  7843. @<Set init...@>=
  7844.  
  7845. mx_sort_ptr=scrp_info;
  7846.  
  7847.  
  7848. @ The desired alphabetic order is specified by the |collate| array; namely,
  7849. |collate[0]==0 <collate[1]<@t$\cdots$@><collate[max_collate]|.  The collate
  7850. array can be set by the style file entry \.{collate}.
  7851.  
  7852. @<Global...@>=
  7853.  
  7854. EXTERN ASCII collate[128]; // collation order.
  7855. EXTERN int max_collate; // Last index in |collate|.  
  7856.  
  7857. @ We use the order $\hbox{null}<\.\ <\hbox{other characters}<\.\_<
  7858. \.A=\.a<\cdots<\.Z=\.z<\.0<\cdots<\.9.$
  7859.  
  7860. @<Set init...@>=
  7861.  
  7862. collate[0] = 0; 
  7863.  
  7864. @ Procedure |unbucket| goes through the buckets and adds nonempty lists to
  7865. the stack, using the collating sequence specified in the |collate| array.
  7866. The parameter to |unbucket| tells the current depth in the buckets.  Any
  7867. two sequences that agree in their first 255 character positions are
  7868. regarded as identical.
  7869.  
  7870. @d INFTY 255 // $\infty$ (approximately).
  7871.  
  7872. @<Part 3@>=@[
  7873.  
  7874. SRTN unbucket FCN((d)) /* Empties buckets having depth |d| */
  7875.     eight_bits d C1("")@;
  7876. {
  7877. int c;  /* Index into |bucket|. {\it Must be |int|.} */
  7878.  
  7879.   for (c=max_collate; c>= 0; c--) if (bucket[collate[c]]) {
  7880.     if (sort_ptr>=scrp_end) OVERFLW("sort levels",ABBREV(max_scraps));
  7881.  
  7882.     sort_ptr++;
  7883.  
  7884.     if (sort_ptr>mx_sort_ptr) mx_sort_ptr = sort_ptr;
  7885.  
  7886.    sort_ptr->depth = (eight_bits)(c==0 ? INFTY : d);
  7887.     sort_ptr->head = bucket[collate[c]]; 
  7888.     bucket[collate[c]] = NULL;
  7889.   }
  7890. }
  7891.  
  7892. @<Sort and output the index@>=
  7893.  
  7894. w_style.indx.collate = x__to_ASCII((outer_char *)w_style.indx.collate);
  7895. max_collate = STRLEN(w_style.indx.collate);
  7896. STRNCPY(collate+1,w_style.indx.collate,max_collate);
  7897.  
  7898. sort_ptr=scrp_info; unbucket(1);
  7899.  
  7900. while (sort_ptr>scrp_info) 
  7901.     {
  7902.       cur_depth=sort_ptr->depth;
  7903.  
  7904.       if (blink[sort_ptr->head-name_dir]==0 || cur_depth==INFTY)
  7905.             @<Output index entries for the list at |sort_ptr|@>@;
  7906.       else @<Split the list at |sort_ptr| into further lists@>;
  7907.     }
  7908.  
  7909. @<Split the list...@>= 
  7910. @{
  7911.   ASCII c;
  7912.  
  7913. @b
  7914.   next_name=sort_ptr->head;
  7915.  
  7916.   do 
  7917.     {
  7918.     cur_name=next_name; next_name=blink[cur_name-name_dir];
  7919.     cur_byte=cur_name->byte_start+cur_depth;
  7920.  
  7921.     if (cur_byte==(cur_name+1)->byte_start) c=0; /* hit end of the name */
  7922.     else 
  7923.     {
  7924.          c = *cur_byte;
  7925.     c = A_TO_LOWER(c);
  7926.      }
  7927.  
  7928.     blink[PTR_DIFF(size_t,cur_name,name_dir)]=bucket[c]; 
  7929.     bucket[c]=cur_name;
  7930.       } 
  7931. while (next_name);
  7932.  
  7933.   --sort_ptr; unbucket((eight_bits)(cur_depth+(eight_bits)1));
  7934. }
  7935.  
  7936. @<Output index...@>= 
  7937. {
  7938. cur_name = sort_ptr->head;
  7939.  
  7940. @<Separate the groups if necessary@>@;
  7941.  
  7942.   do 
  7943.     {
  7944.     if(cur_name->defined_type(language) < 0x80)
  7945.         { /* Write index entry for one identifier. */
  7946.         OUT_STR(w_style.indx.item_0);
  7947. @.\\:@>
  7948.         @<Output the name at |cur_name|@>;
  7949.         @<Output the cross-references at |cur_name|@>;
  7950.         }
  7951.  
  7952.     cur_name = blink[cur_name-name_dir];
  7953.     } 
  7954. while (cur_name);
  7955.  
  7956. --sort_ptr;
  7957. }
  7958.  
  7959. @ Here we insert an optional macro between the different groups.
  7960.  
  7961. @d NON_TEX_MACRO '\1'
  7962.  
  7963. @<Separate the groups...@>=
  7964. {
  7965. ASCII letter = *cur_name->byte_start; 
  7966.  
  7967. /* In some special cases in \Cpp, the identifier may be a \TeX\ macro
  7968. beginning with~'\.\\' at this point. We must then take special precautions.
  7969. In particular, we assign a non-null, non-printable value to |letter|. */
  7970. if(letter == @'\\' && cur_name->ilk==normal && language!=TEX) 
  7971.     letter = NON_TEX_MACRO; 
  7972. else letter = A_TO_LOWER(letter);
  7973.  
  7974. if(letter != last_letter)
  7975.     {
  7976.     if(last_letter)    OUT_STR(w_style.indx.group_skip); /* Separate groups,
  7977. but not for the very first one. */
  7978.  
  7979.     if(w_style.indx.lethead_flag && letter != NON_TEX_MACRO) 
  7980.         {
  7981.         OUT_STR(w_style.indx.lethead_prefix);
  7982.  
  7983.         switch(letter)
  7984.             {
  7985.             @<Special string cases@>: out(@'\\');
  7986.             }
  7987.         out((w_style.indx.lethead_flag > 0 ? A_TO_UPPER(letter) :
  7988. A_TO_LOWER(letter)));
  7989.  
  7990.         OUT_STR(w_style.indx.lethead_suffix);
  7991.         }
  7992.     }
  7993.  
  7994. last_letter = letter;
  7995. }
  7996.  
  7997. @<Output the name...@>=
  7998. @{
  7999. boolean output_type;
  8000.  
  8001. @b
  8002. switch (cur_name->ilk) 
  8003.     {
  8004.   case normal: 
  8005.     output_type = IDENTIFIER;
  8006.  
  8007.     if(is_intrinsic(cur_name)) OUT_STR(pfmt->intrinsic);
  8008.         // E.g., |sqrt|.
  8009.     else if(is_keyword(cur_name)) OUT_STR(pfmt->keyword);
  8010.         // E.g., |@r BLOCKSIZE|.
  8011.     else 
  8012.         if(language==TEX) OUT_STR(pfmt->typewritr); 
  8013.             // E.g., \.{\\hfill}.
  8014.         else if (length(cur_name)==1) 
  8015.             OUT_STR(pfmt->short_id); // E.g., |a|.
  8016.         else @<Output the appropriate identifier prefix@>@;
  8017.      break;
  8018. @.\\\AT!@>
  8019. @.\\|@>
  8020. @.\\\\@>
  8021.   case roman: output_type = INDEX_ENTRY; @+ break;
  8022.   case wildcard: OUT_STR(pfmt->wildcrd); @+ output_type = INDEX_ENTRY; @+ break;
  8023. @.\\9@>
  8024.   case typewriter: OUT_STR(pfmt->typewritr); 
  8025.     output_type = INDEX_ENTRY; @+ break;
  8026. @.\\.@>
  8027.   default: 
  8028.     OUT_STR(pfmt->reserved); 
  8029.     output_type = IDENTIFIER; @+ break; // E.g., |int|.
  8030. @.\\\&@>
  8031.     }
  8032.  
  8033. out_name(output_type,cur_name);
  8034. }
  8035.  
  8036. @ Section numbers that are to be underlined are enclosed in
  8037. `\.{\\[}$\,\ldots\,$\.]'.
  8038.  
  8039. @d ENCAP YES
  8040. @d NO_ENCAP NO
  8041.  
  8042. @<Output the cross-references...@>=
  8043.  
  8044. @<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>;
  8045.  
  8046. OUT_STR(w_style.indx.delim_0); /* Immediately after identifier. */
  8047.  
  8048. WHILE()
  8049.     {
  8050.     cur_val=cur_xref->num;
  8051.  
  8052.       if (cur_val<def_flag) out_mod(cur_val,ENCAP);
  8053.       else 
  8054.         {
  8055.         OUT_STR(w_style.indx.underline_prefix); 
  8056.         out_mod(cur_val-def_flag,ENCAP);
  8057.         OUT_STR(w_style.indx.underline_suffix);
  8058.         }
  8059. @.\\[@>
  8060.  
  8061. /* If the language of this module isn't the global language, mark it in the
  8062. |w_style|. */
  8063.     if((LANGUAGE)cur_xref->Language != global_language)
  8064.         {
  8065.         char temp[50];
  8066.  
  8067.         sprintf(temp,"%s%s%s",w_style.indx.language_prefix,
  8068.             language_symbol((LANGUAGE)cur_xref->Language),
  8069.             w_style.indx.language_suffix); 
  8070.         OUT_STR(temp);
  8071.         }
  8072.  
  8073.     cur_xref=cur_xref->xlink;
  8074.  
  8075.     if(cur_xref == xmem) break;
  8076.     OUT_STR(w_style.indx.delim_n); /* Between identifiers. */
  8077.     } 
  8078.  
  8079. out(@'.'); @+ fin_line();
  8080.  
  8081. @ List inversion is best thought of as popping elements off one stack and
  8082. pushing them onto another. In this case |cur_xref| will be the head of
  8083. the stack that we push things onto.
  8084.  
  8085. @<Invert the cross-reference list at |cur_name|, making |cur_xref| the head@>=
  8086.  
  8087. this_xref = (xref_pointer)cur_name->xref; cur_xref=xmem;
  8088.  
  8089. do 
  8090.     {
  8091.       next_xref=this_xref->xlink; this_xref->xlink=cur_xref;
  8092.       cur_xref=this_xref; this_xref=next_xref;
  8093.     } 
  8094. while (this_xref!=xmem);
  8095.  
  8096. @ The following recursive procedure walks through the tree of module names and
  8097. prints them.
  8098. @^recursion@>
  8099.  
  8100. @<Part 3@>=@[
  8101.  
  8102. SRTN mod_print FCN((p)) /* Print all module names in subtree |p|. */
  8103.     name_pointer p C1("")@;
  8104. {
  8105.   if (p) 
  8106.     {
  8107.     mod_print(p->llink); OUT_STR("\\:");
  8108. @.\\:@>
  8109.     tok_ptr=tok_mem+1; text_ptr=tok_start+1; scrp_ptr=scrp_info; ini_stack;
  8110.     APP_FLAG(mod,p,name_dir);
  8111.     make_output();
  8112.     footnote(0); /* |cur_xref| was set by |make_output| */
  8113.     fin_line();
  8114.  
  8115.     mod_print(p->rlink);
  8116.       }
  8117. }
  8118.  
  8119. @
  8120. @<Output the index@>=
  8121. {
  8122. writing(YES,temp_ndx);
  8123. if(tex_file == stdout) puts("");
  8124. NEW_TeX(temp_ndx);
  8125.  
  8126. if (change_exists) 
  8127.     {
  8128.     @<Tell about changed modules@>;
  8129.     fin_line(); 
  8130.     fin_line(); 
  8131.     }
  8132.  
  8133. OUT_STR(w_style.indx.preamble); @+ fin_line();
  8134. @.\\Winx@>
  8135.  
  8136. @<Do the first pass of sorting@>;
  8137. @<Sort and output the index@>;
  8138.  
  8139. OUT_STR(w_style.indx.postamble); @+ fin_line();
  8140. @.\\Wfin@>
  8141. }
  8142.  
  8143. @<Output all the module names@>=
  8144. {
  8145. writing(BOOLEAN(!prn_index),temp_mds);
  8146. NEW_TeX(temp_mds);
  8147.  
  8148. OUT_STR(w_style.modules.preamble); @+ fin_line();
  8149. @.\\Wmods@>
  8150.  
  8151. mod_print(root);
  8152.  
  8153. OUT_STR(w_style.modules.postamble); @+ fin_line();
  8154. }
  8155.  
  8156. @ Statistics are printed when the command-line option~\.{-s} is used.
  8157.  
  8158. @<Part 3@>=@[
  8159.  
  8160. SRTN see_wstatistics(VOID)
  8161. {
  8162. CLR_PRINTF(info,("\n\nMEMORY USAGE STATISTICS:\n"));
  8163.  
  8164. STAT0("names",sizeof(*name_ptr),
  8165.     SUB_PTRS(name_ptr,name_dir),max_names,UPPER(max_names),",");
  8166.  
  8167. STAT0("cross-references",sizeof(*xref_ptr),
  8168.     SUB_PTRS(xref_ptr,xmem),max_refs,UPPER(max_refs),",");
  8169.  
  8170. STAT0("bytes",sizeof(*byte_ptr),
  8171.     SUB_PTRS(byte_ptr,byte_mem),max_bytes,UPPER(max_bytes),";");
  8172.  
  8173. CLR_PRINTF(info,(" parsing required\n"));
  8174.  
  8175. STAT0("scraps",sizeof(*mx_scr_ptr),
  8176.     SUB_PTRS(mx_scr_ptr,scrp_base),max_scraps,UPPER(max_scraps),",");
  8177.  
  8178. STAT0("texts",sizeof(*mx_text_ptr),
  8179.     SUB_PTRS(mx_text_ptr,tok_start),max_texts,UPPER(max_texts),",");
  8180.  
  8181. STAT0("tokens",sizeof(*mx_tok_ptr),
  8182.     SUB_PTRS(mx_tok_ptr,tok_mem),max_toks,UPPER(max_toks_w),",");
  8183.  
  8184. STAT0("stack levels",sizeof(*mx_stck_ptr),
  8185.     SUB_PTRS(mx_stck_ptr,stack),stck_size,UPPER(stck_size_w),";");
  8186.  
  8187. CLR_PRINTF(info,(" sorting required"));
  8188.  
  8189. printf(" %lu level(s).\n",SUB_PTRS(mx_sort_ptr,scrp_info));
  8190.  
  8191. mem_avail(1); /* How much memory left at end of run? */
  8192. }
  8193.  
  8194. @ The following routines are invoked by \.{common.web}, but are  used only by
  8195. \.{TANGLE}. 
  8196. @<Part 3@>=@[
  8197.  
  8198. SRTN predefine_macros(VOID)
  8199. {}
  8200.  
  8201. SRTN open_out(VOID)
  8202. {}
  8203.  
  8204. boolean was_opened FCN((name,global_scope,pname,pptr))
  8205.     CONST outer_char HUGE *name C0("")@;
  8206.     boolean global_scope C0("")@;
  8207.     outer_char HUGE * HUGE *pname C0("")@;
  8208.     FILE **pptr C1("")@;
  8209. {
  8210. *pname = GET_MEM("*pname",STRLEN(name)+1,outer_char);
  8211. STRCPY(*pname,name);
  8212.  
  8213. return NO;
  8214. }
  8215.  
  8216. SRTN ini_tokens FCN((language0))
  8217.     LANGUAGE language0 C1("")@;
  8218. {}
  8219.  
  8220. @* STYLE FILE. The style file is common to \FWEAVE\ and \FTANGLE. See
  8221. \.{style.web}. 
  8222.  
  8223. @<Include...@>=
  8224.  
  8225. #include "map.h" // Relations between style file keywords and internal arrays.
  8226.  
  8227. @* INDEX.  If you have read and understood the code for Phase~III above,
  8228. you know what is in this index and how it got here. All modules in which an
  8229. identifier is used are listed with that identifier, except that reserved
  8230. words are indexed only when they appear in format definitions, and the
  8231. appearances of identifiers in module names are not indexed. Underlined
  8232. entries correspond to where the identifier was declared. Error messages,
  8233. control sequences put into the output, and a few other things like
  8234. ``recursion'' are indexed here too.
  8235.